package pkg import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( NETSELFALLOWRE = regexp.MustCompile(`(?i)defaults\s+{((.|\n)*?)}`) COLONSPLITRE = regexp.MustCompile(`(\S+):(\S+)`) ) type ( SelfAllow struct { Defaults []*ServicePort `json:"default"` } ) func ParseSelfAllow(s string) *SelfAllow { a := new(SelfAllow) a.Parse(s) return a } func (a *SelfAllow) Parse(s string) { for _, r := range COLONSPLITRE.FindAllStringSubmatch(util.RegexpString(NETSELFALLOWRE, s), -1) { a.Defaults = append(a.Defaults, &ServicePort{ Proto: r[1], Port: r[2], }) } }