golifehk/datasources/mtr/bus/QueryResult.go

49 lines
1.0 KiB
Go
Raw Normal View History

2022-09-14 13:21:39 +00:00
package bus
import (
"fmt"
"strings"
)
type QueryResult struct {
Schedules *map[BusStop] *BusStopBuses
Lang string
Error error
}
func ( result QueryResult ) Message() string {
if result.Error != nil {
return fmt.Sprintf( "%s", result.Error )
}
sb := strings.Builder{}
for busStop, buses := range *result.Schedules {
if busStop.PrevStop() != nil {
sb.WriteString( (*busStop.PrevStop().Name)[ result.Lang ] )
sb.WriteString( " > *" )
}
sb.WriteString( (*busStop.Name)[ result.Lang ] )
sb.WriteString( "*" )
if busStop.NextStop() != nil {
sb.WriteString( " > " )
sb.WriteString( (*busStop.NextStop().Name)[ result.Lang ] )
}
sb.WriteString( "\n" )
for _, bus := range buses.Buses {
sb.WriteString( " * " )
sb.WriteString( bus.ETAText )
sb.WriteString( "\n" )
}
sb.WriteString( "\n" )
}
return sb.String()
}