Skip to content
Snippets Groups Projects
Commit bf2ab576 authored by gjahn's avatar gjahn
Browse files

Fix health endpoint

it appears that order matters; using ctx.JSON overrides c.Type; but
instead of shuffling the lines around, the JSON string is generated
by *foot*, which allows to keep header setting at the beginning of
the function.
parent 196c33ae
No related branches found
No related tags found
No related merge requests found
......@@ -21,25 +21,29 @@ func SetRoutes( router *f.App, config *configuration.Config, healthiness *bool )
router.Get( "/health", func( c *f.Ctx ) error {
type response struct {
Status string `json:"status" validate:"oneof=passed failed"`
Status string `json:"status" validate:"oneof=pass fail"`
}
c.Type( "json", "utf-8" )
c.Set( "Content-Type", "application/health+json; charset=utf-8" )
var res response
var res *response
if *healthiness == false {
res = response{
Status: "failed",
res = &response{
Status: "fail",
}
c.Status( http.StatusServiceUnavailable )
} else {
res = response{
Status: "passed",
res = &response{
Status: "pass",
}
c.Status( http.StatusOK )
}
return c.JSON( res )
resJson, err := json.Marshal( res )
if err != nil {
return err
}
return c.SendString( string( resJson ) )
})
......
......@@ -88,7 +88,7 @@ func TestHealthRoute( t *testing.T ){
status := bodyContent[ "status" ].( string )
assert.Equal( t, http.StatusOK, res.StatusCode )
assert.Nil( t, err )
assert.Equal( t, "passed", status )
assert.Equal( t, "pass", status )
*healthiness = false
......@@ -98,7 +98,7 @@ func TestHealthRoute( t *testing.T ){
status = bodyContent[ "status" ].( string )
assert.Equal( t, http.StatusServiceUnavailable, res.StatusCode )
assert.Nil( t, err )
assert.Equal( t, "failed", status )
assert.Equal( t, "fail", status )
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment