This repository was archived by the owner on Oct 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -51,16 +51,19 @@ func main() {
5151 mc.Destroy ()
5252}
5353
54- // Health output is in JSON format. Don't forget to add json tags .
54+ // Health output will be in JSON format.
5555type exampleHealthOutput struct {
5656 Status string ` json:"status"`
5757}
5858
5959// Our health callback routine.
60- func healthCallback () interface {} {
61- return exampleHealthOutput{
60+ func healthCallback () string {
61+ state := exampleHealthOutput{
6262 Status: " ok" ,
6363 }
64+
65+ j , _ := json.Marshal (state)
66+ return string (j)
6467}
6568```
6669
Original file line number Diff line number Diff line change @@ -10,11 +10,13 @@ import (
1010
1111func (mws * Controller ) getHealthHandler () webserver.HandlerFunc {
1212 return func (req * request.RequestContext ) error {
13- // Get current state from callback
14- state := mws .healthCallback ()
13+ // Get current health status from callback
14+ status := mws .healthCallback ()
1515
16- // Encode and send output
17- req .WriteJSON (state )
16+ // Send output
17+ if len (status ) > 0 {
18+ req .WriteString (status )
19+ }
1820 req .Success ()
1921
2022 // Done
Original file line number Diff line number Diff line change @@ -60,8 +60,8 @@ type Options struct {
6060 Middlewares []webserver.MiddlewareFunc
6161}
6262
63- // HealthCallback indicates a function that returns an object that will be returned as a JSON output.
64- type HealthCallback func () interface {}
63+ // HealthCallback indicates a function that returns a string that will be returned as the output.
64+ type HealthCallback func () string
6565
6666// -----------------------------------------------------------------------------
6767
Original file line number Diff line number Diff line change 11package metrics_test
22
33import (
4+ "encoding/json"
45 "fmt"
56 "math/rand"
67 "os"
@@ -129,10 +130,13 @@ func TestWebServer(t *testing.T) {
129130
130131// -----------------------------------------------------------------------------
131132
132- func healthCallback () interface {} {
133- return State {
133+ func healthCallback () string {
134+ state := State {
134135 System : "all services running" ,
135136 }
137+
138+ j , _ := json .Marshal (state )
139+ return string (j )
136140}
137141
138142func openBrowser (url string ) {
You can’t perform that action at this time.
0 commit comments