func (server *Server) PostPaths(ctx *web.Context) string { var input struct { Paths []geotypes.NodeEdge Country string SpeedProfile int } var ( computed []geotypes.Path ) if err := json.NewDecoder(ctx.Request.Body).Decode(&input); err != nil { content, _ := ioutil.ReadAll(ctx.Request.Body) ctx.Abort(400, "Couldn't parse JSON: "+err.Error()+" in '"+string(content)+"'") return "" } else { var err error computed, err = server.Via.CalculatePaths(input.Paths, input.Country, input.SpeedProfile) if err != nil { ctx.Abort(422, "Couldn't resolve addresses: "+err.Error()) return "" } } res, err := json.Marshal(computed) if err != nil { ctx.Abort(500, "Couldn't serialize paths: "+err.Error()) return "" } ctx.Header().Set("Access-Control-Allow-Origin", "*") ctx.ContentType("application/json") return string(res) }
func rss(ctx *web.Context) string { feed := _createFeed() ctx.Header().Set("Content-Type", "application/xml") if feed == nil { return "<!-- error -->" } text, err := feed.ToRss() if err != nil { fmt.Println(err) return "<!-- error -->" } return text }
func NewContext(wctx *web.Context) *Context { wctx.Header().Set("Content-Type", "application/json") return &Context{wctx} }