package kmb import ( query "github.com/tgckpg/golifehk/query" ) type RouteStop struct { BusStop *BusStop RouteId string `json:"route"` ServiceType string `json:"service_type"` Direction string `json:"bound"` StationSeq int `json:"seq,string"` StationId string `json:"stop"` RouteStops *map[int] *RouteStop query.Searchable } type RouteStops struct { Type string `json:"type"` Version string `json:"version"` DateCreated string `json:"generated_timestamp"` RouteStops [] *RouteStop `json:"data"` } func ( routeStop RouteStop ) PrevStop() *RouteStop { if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq - 1 ]; hasKey { return v } return nil } func ( routeStop RouteStop ) NextStop() *RouteStop { if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq + 1 ]; hasKey { return v } return nil } func ( this *RouteStop ) Reload() { searchData := [] *string{} busStop := *this.BusStop searchData = append( searchData, &busStop.Name_en ) searchData = append( searchData, &busStop.Name_tc ) this.Key = &this.RouteId this.SearchData = &searchData } type ByRoute [] *RouteStop func (a ByRoute) Len() int { return len(a) } func (a ByRoute) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByRoute) Less(i, j int) bool { _a := *a[i] _b := *a[j] if _a.RouteId == _b.RouteId { if _a.Direction == _b.Direction { return _a.ServiceType < _b.ServiceType } return _a.Direction < _b.Direction } return _a.RouteId < _b.RouteId }