package parsers import "regexp" var routeStatusRE = regexp.MustCompile(`\d+\s+((?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+((?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+((?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)`) type ( // RoutesStatus is an aggregate type to house a listing of route // entries RoutesStatus struct { Routes []RouteStatus `json:"routes"` } // RouteStatus is the single parsed entry in the routing-table RouteStatus struct { Destination string `json:"destination"` Netmask string `json:"netmask"` Gateway string `json:"gateway"` Port string `json:"port"` Cost string `json:"cost"` Type string `json:"type"` Uptime string `json:"uptime"` } ) // Parse method is used to implement type population of a given string // using parsers to populate the method receiver. func (r *RoutesStatus) Parse(s *string) { for _, raw := range routeStatusRE.FindAllStringSubmatch(*s, -1) { r.Routes = append(r.Routes, RouteStatus{ Destination: raw[1], Netmask: raw[2], Gateway: raw[3], Port: raw[4], Cost: raw[5], Type: raw[6], Uptime: raw[7], }) } }