Archived
0
0
Fork 0
This repository has been archived on 2024-05-09. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
nextrip/bushandler.go
2018-05-26 09:08:36 -05:00

34 lines
573 B
Go

package main
import (
"encoding/json"
"fmt"
"strconv"
log "github.com/Sirupsen/logrus"
"github.com/valyala/fasthttp"
)
func busHandler(ctx *fasthttp.RequestCtx) {
queryArgs := ctx.QueryArgs()
stop, err := strconv.Atoi(string(queryArgs.Peek("stop_id")))
if err != nil {
fmt.Fprint(ctx, "bad stop specified")
log.Error(err)
return
}
s, err := env.GetDepartures(stop)
if err != nil {
log.Error(err)
return
}
b, err := json.Marshal(s)
if err != nil {
log.Error(err)
}
if _, err := fmt.Fprint(ctx, string(b)); err != nil {
log.Error(err)
}
}