package pkg import ( "errors" "strings" ) type HTMLProfile struct { ProfileCommon ContentDetection string `json:"content_detection"` //content-detection disabled ContentSelection []string `json:"content_selection"` //content-selection { text/html text/xhtml } Rules []string `json:"rules"` //rules none } func ParseHTML(raw string) (*HTMLProfile, error) { p := new(HTMLProfile) p.ContentSelection = []string{} p.Rules = []string{} split := strings.Split(raw, "\n") if !strings.Contains(split[0], "list ltm profile html") { return nil, errors.New("not an html profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "content-detection": p.ContentDetection = f[1] case "content-selection": if f[1] != "none" { p.ContentSelection = append(p.ContentSelection, f[2:len(f)-1]...) } case "rules": if f[1] != "none" { p.Rules = append(p.Rules, f[2:len(f)-1]...) } } } return p, nil }