testserver tweaks.
This commit is contained in:
parent
80d6be9849
commit
f22f247d3b
1 changed files with 58 additions and 41 deletions
|
@ -8,12 +8,18 @@ import (
|
|||
"github.com/wcharczuk/go-web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := web.New()
|
||||
app.SetName("Chart Test Server")
|
||||
app.SetLogger(web.NewStandardOutputLogger())
|
||||
app.GET("/", func(rc *web.RequestContext) web.ControllerResult {
|
||||
func chartHandler(rc *web.RequestContext) web.ControllerResult {
|
||||
format, err := rc.RouteParameter("format")
|
||||
if err != nil {
|
||||
format = "png"
|
||||
}
|
||||
|
||||
if format == "png" {
|
||||
rc.Response.Header().Set("Content-Type", "image/png")
|
||||
} else {
|
||||
rc.Response.Header().Set("Content-Type", "image/svg+xml")
|
||||
}
|
||||
|
||||
c := chart.Chart{
|
||||
Title: "A Test Chart",
|
||||
TitleStyle: chart.Style{
|
||||
|
@ -46,12 +52,23 @@ func main() {
|
|||
},
|
||||
}
|
||||
|
||||
err := c.Render(chart.PNG, rc.Response)
|
||||
if format == "png" {
|
||||
err = c.Render(chart.PNG, rc.Response)
|
||||
} else {
|
||||
err = c.Render(chart.SVG, rc.Response)
|
||||
}
|
||||
if err != nil {
|
||||
return rc.API().InternalError(err)
|
||||
}
|
||||
rc.Response.WriteHeader(http.StatusOK)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := web.New()
|
||||
app.SetName("Chart Test Server")
|
||||
app.SetLogger(web.NewStandardOutputLogger())
|
||||
app.GET("/", chartHandler)
|
||||
app.GET("/:format", chartHandler)
|
||||
log.Fatal(app.Start())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue