package pkg import ( "errors" "strconv" "strings" ) type TFTPProfile struct { ProfileCommon IdleTimeout int `json:"idle_timeout"` LogProfile string `json:"log_profile"` LogPublisher string `json:"log_publisher"` } func ParseTFTP(raw string) (*TFTPProfile, error) { p := new(TFTPProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile tftp") { return nil, errors.New("not a tftp profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "idle-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.IdleTimeout = i case "log-profile": p.LogProfile = strings.Join(f[1:], " ") case "log-publisher": p.LogPublisher = strings.Join(f[1:], " ") } } return p, nil }