package pkg import ( "errors" "strconv" "strings" ) type ICAPProfile struct { ProfileCommon HeaderFrom string `json:"header_from"` //header-from none Host string `json:"host"` //host none PreviewLength int `json:"preview_length"` //preview-length 0 Referer string `json:"referer"` //referer none URI string `json:"uri"` //uri none UserAgent string `json:"user_agent"` //user-agent none } func ParseICAP(raw string) (*ICAPProfile, error) { p := new(ICAPProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile icap") { return nil, errors.New("not an icap profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "header-from": p.HeaderFrom = strings.Join(f[1:], " ") case "host": p.Host = strings.Join(f[1:], " ") case "preview-length": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.PreviewLength = i case "referer": p.Referer = strings.Join(f[1:], " ") case "uri": p.URI = strings.Join(f[1:], " ") case "user-agent": p.UserAgent = strings.Join(f[1:], " ") } } return p, nil }