package asaModels import ( "regexp" "strconv" ) type ( HTTPConfig struct { Server HTTPServer `json:"server"` Allowed []HTTPAllowed `json:"allowed"` } HTTPServer struct { Enabled bool `json:"enabled"` Port int `json:"port"` } HTTPAllowed struct { Net string `json:"network"` Mask string `json:"netmask"` Int string `json:"interface"` } ) var ( regexHTTP = regexp.MustCompile(`http (\S+) (\S+)(?: (\S+))?`) ) func (h *HTTPConfig) Parse(s string) error { h.Server.Enabled = false m := regexHTTP.FindAllStringSubmatch(s, -1) for _, match := range m { if match[1] == "server" && match[2] == "enable" { h.Server.Enabled = true if match[3] == "" { match[3] = "443" } port, err := strconv.Atoi(match[3]) if err != nil { return err } h.Server.Port = port continue } h.Allowed = append(h.Allowed, HTTPAllowed{ Net: match[1], Mask: match[2], Int: match[3], }) } return nil }