package asaModels import "regexp" type ( DHCPServer struct { Ranges map[string]dhcpRange `json:"ranges"` } dhcpRange struct { Begin string End string Enabled bool } ) func (d *DHCPServer) Parse(s string) error { d.Ranges = make(map[string]dhcpRange) // Find available ranges addressLines := regexp.MustCompile(`dhcpd address (\S+) (\S+)`).FindAllStringSubmatch(s, -1) for _, r := range addressLines { curRange := dhcpRange{} // Break out the range to a begin and end m := regexp.MustCompile(`(\S+)-(\S+)`).FindStringSubmatch(r[1]) if len(m) == 3 { curRange.Begin = m[1] curRange.End = m[2] } // Step through the enable lines and look for a match, if we find one, set variable to true enables := regexp.MustCompile(`dhcpd enable (\S+)`).FindAllStringSubmatch(s, -1) for _, line := range enables { if line[1] == r[2] { curRange.Enabled = true // Break loop early, no reason to check remaining lines break } } d.Ranges[r[2]] = curRange } return nil }