package parsers import "regexp" // used with 'show ssl key *' var keysRe = regexp.MustCompile(`\s*(\d+)\s+:\s+(\S+)\s*(\n|$)`) type ( // AdxKeys is the aggregate type for all ADX keys on an ADX AdxKeys struct { Key []AdxKey `json:"keys"` } // AdxKey defines the parsed elements from a key configuration AdxKey struct { Index string `json:"index"` Name string `json:"name"` } ) // Parse method is used to implement type population of a given string // using parsers to populate the method receiver. func (a *AdxKeys) Parse(s *string) { for _, v := range keysRe.FindAllStringSubmatch(*s, -1) { a.Key = append(a.Key, AdxKey{Index: v[1], Name: v[2]}) } }