package wafModels import ( "errors" "regexp" ) type ( Inventory struct { Items []InventoryItem `json:"items"` } InventoryItem struct { Name string `json:"name"` Description string `json:"descr"` PID string `json:"pid"` VID string `json:"vid"` SN string `json:"serial_number"` } ) func (i *Inventory) Parse(s string) error { f := regexp.MustCompile(`Name: \"(\w+)\",.*\"(.*)\"\nPID: (\w+).*, VID: (\w+).*, SN: (\w+)`).FindAllStringSubmatch(s, -1) if len(f) < 1 { return errors.New("No matches found") } for _, match := range f { if len(match) != 6 { continue } i.Items = append(i.Items, InventoryItem{ Name: match[1], Description: match[2], PID: match[3], VID: match[4], SN: match[5], }) } return nil }