package pkg import "regexp" var ( PROVISIONLVLRE = regexp.MustCompile(`sys\s+provision\s+(\S+)\s+{\s+level\s+(\S+)\s*\n`) ) type ( Provision struct { Afm *Prov `json:"afm"` Am *Prov `json:"am"` Apm *Prov `json:"apm"` Asm *Prov `json:"asm"` Avr *Prov `json:"avr"` Gtm *Prov `json:"gtm"` Lc *Prov `json:"lc"` Ltm *Prov `json:"ltm"` Swg *Prov `json:"swg"` } Prov struct { Level string `json:"level"` } ) func ParseProvision(s string) *Provision { p := new(Provision) p.Parse(s) return p } func (P *Provision) Parse(s string) { for _, p := range PROVISIONLVLRE.FindAllStringSubmatch(s, -1) { switch p[1] { case "afm": P.Afm = &Prov{ Level: p[2], } case "am": P.Am = &Prov{ Level: p[2], } case "apm": P.Apm = &Prov{ Level: p[2], } case "asm": P.Asm = &Prov{ Level: p[2], } case "avr": P.Avr = &Prov{ Level: p[2], } case "gtm": P.Gtm = &Prov{ Level: p[2], } case "lc": P.Lc = &Prov{ Level: p[2], } case "ltm": P.Ltm = &Prov{ Level: p[2], } case "swg": P.Swg = &Prov{ Level: p[2], } } } }