1 回答
TA贡献1797条经验 获得超6个赞
只需将它们映射到新类型:
func main() {
flag.Parse()
c := gombta.Client{APIKey: apikey, URL: apiurl}
// get a list of routes by type
d, err := c.GetRoutes(format)
check(err)
var toPrint interface{}
if typeid == 9999 {
type Result struct {
RouteType string `json:"route_type"`
ModeName string `json:"mode_name"`
}
rs := []Result{}
for _, m := range d.Mode {
rs = append(rs, Result{
RouteType: m.RouteType,
ModeName: m.ModeName,
})
}
toPrint = rs
} else {
type Result struct {
RouteID string `json:"route_id"`
RouteName string `json:"route_name"`
}
rs := []Result{}
for _, m := range d.Mode {
if fmt.Sprint(typeid) == m.RouteType {
for _, r := range m.Route {
rs = append(rs, Result{
RouteID: r.RouteID,
RouteName: r.RouteName,
})
}
}
}
toPrint = rs
}
j, err := json.MarshalIndent(toPrint, "", " ")
fmt.Printf("RouteTypes: ")
os.Stdout.Write(j)
}
- 1 回答
- 0 关注
- 169 浏览
添加回答
举报