type match struct { Time string`json:"time,omitempty"` DateTime string`json:"datetime,omitempty"` HomeTeam team `json:"home_team,ommitempty"` AwayTeam team `json:"away_team,omitempty"` Winner string`json:"winner,omitempty"` }
type team struct { Country string`json:"country,omitempty"` Code string`json:"code,omitempty"` Goals int`json:"goals,omitempty"` }
funcprogressBar(percentage int)string { var bar string
switch percentage { case0: bar = multiply('-', ScreenWidth) case100: bar = colorize(multiply('-', ScreenWidth)) default: completed := int(float64(ScreenWidth) / 100.0 * float64(percentage)) bar = colorize(multiply('-', completed-1)+"o") + multiply('-', ScreenWidth-completed) }
return bar }
Controller
Controller 部分就是将 Model 部分和 view 部分代码整合在一起。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
funcmain() { matches, err := fetch("matches/today") if err != nil { log.Fatal(err) } for i, match := range matches { if i == 0 { fmt.Println() } fmt.Println(prettify(match)) if i != len(matches)-1 { fmt.Println() } } }