package pkg import ( "errors" "strings" ) type FTPProfile struct { ProfileCommon AllowFTPs string `json:"allow_ftps"` InheritParentProfile string `json:"inherit_parent_profile"` LogProfile string `json:"log_profile"` LogPublisher string `json:"log_publisher"` Port string `json:"port"` Security string `json:"security"` TranslateExtended string `json:"translate_extended"` } func ParseFTPProfile(raw string) (*FTPProfile, error) { p := new(FTPProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile ftp") { return nil, errors.New("not an ftp profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "allow-ftps": p.AllowFTPs = f[1] case "inherit-parent-profile": p.InheritParentProfile = f[1] case "log-profile": p.LogProfile = strings.Join(f[1:], " ") case "log-publisher": p.LogPublisher = strings.Join(f[1:], " ") case "port": p.Port = strings.Join(f[1:], " ") case "security": p.Security = f[1] case "translate-extended": p.TranslateExtended = f[1] } } return p, nil }