package pkg import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( LISTROUTE = regexp.MustCompile(`(?i)(|n)et\s+route\s+(\S+)\s+{((.|\n)*?)(\n\w|$)`) LISTRTGATEWAYRE = regexp.MustCompile(`(?i)gateway|gw\s+(\S+)`) NETWORKRE = regexp.MustCompile(`(?i)network\s+(\S+)`) LISTRTBLACKHOLRE = regexp.MustCompile(`(?i)(blackhole)`) ) type Route struct { Name string `json:"name"` Gateway string `json:"gateway"` Network string `json:"network"` Blackhole bool `json:"blackhole"` Description *string `json:"description"` } func ParseRoute(i []string) *Route { return &Route{ Gateway: util.RegexpString(LISTRTGATEWAYRE, i[3]), Network: util.RegexpString(NETWORKRE, i[3]), Blackhole: LISTRTBLACKHOLRE.MatchString(i[3]), Description: util.RegexpFindStringPtr(descriptionRegex, i[3]), } } // ParseRoutes : Parse list net route func ParseRoutes(s string) ([]*Route, error) { var m []*Route for _, i := range LISTROUTE.FindAllStringSubmatch(s, -1) { l := ParseRoute(i) l.Name = i[2] m = append(m, l) } return m, nil }