package pkg import ( "errors" "strconv" "strings" ) type OneConnectProfile struct { ProfileCommon IdleTimeoutOverride string `json:"idle_timeout_override"` LimitType string `json:"limit_type"` MaxAge int `json:"max_age"` MaxReuse int `json:"max_reuse"` MaxSize int `json:"max_size"` SharePools string `json:"share_pools"` SourceMask string `json:"source_mask"` } func ParseOneConnectProfile(raw string) (*OneConnectProfile, error) { p := new(OneConnectProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile one-connect") { return nil, errors.New("not a one-connect profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "idle-timeout-override": p.IdleTimeoutOverride = strings.Join(f[1:], " ") case "limit-type": p.LimitType = strings.Join(f[1:], " ") case "max-age": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxAge = i case "max-reuse": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxReuse = i case "max-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxSize = i case "share-pools": p.SharePools = strings.Join(f[1:], " ") case "source-mask": p.SourceMask = strings.Join(f[1:], " ") } } return p, nil }