package pkg import ( "errors" "strconv" "strings" ) type RequestAdaptProfile struct { ProfileCommon AllowHTTP10 string `json:"allow_http_10"` Enabled string `json:"enabled"` InternalVirtual string `json:"internal_virtual"` PreviewSize int `json:"preview_size"` ServiceDownAction string `json:"service_down_action"` Timeout int `json:"timeout"` } func ParseRequestAdapt(raw string) (*RequestAdaptProfile, error) { p := new(RequestAdaptProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile request-adapt") { return nil, errors.New("not a request-adapt profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "allow-http-10": p.AllowHTTP10 = f[1] case "enabled": p.Enabled = f[1] case "internal-virtual": p.InternalVirtual = strings.Join(f[1:], " ") case "preview-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.PreviewSize = i case "service-down-action": p.ServiceDownAction = f[1] case "timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.Timeout = i } } return p, nil }