package parsers import "regexp" // used with 'show ssl cert *' var certsRe = regexp.MustCompile(`\s*(\d+)\s+:\s+(\S+)\s*(\n|$)`) type ( // AdxCerts type is the aggregate data structure to define all the // certs on an ADX. AdxCerts struct { Cert []AdxCert `json:"certificates"` } // AdxCert type is the actual parsed data from a device certificate AdxCert 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 *AdxCerts) Parse(s *string) { for _, v := range certsRe.FindAllStringSubmatch(*s, -1) { a.Cert = append(a.Cert, AdxCert{Index: v[1], Name: v[2]}) } }