This repository was archived by the owner on Oct 14, 2024. It is now read-only.
File tree 4 files changed +20
-11
lines changed
4 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -51,16 +51,19 @@ func main() {
51
51
mc.Destroy ()
52
52
}
53
53
54
- // Health output is in JSON format. Don't forget to add json tags .
54
+ // Health output will be in JSON format.
55
55
type exampleHealthOutput struct {
56
56
Status string ` json:"status"`
57
57
}
58
58
59
59
// Our health callback routine.
60
- func healthCallback () interface {} {
61
- return exampleHealthOutput{
60
+ func healthCallback () string {
61
+ state := exampleHealthOutput{
62
62
Status: " ok" ,
63
63
}
64
+
65
+ j , _ := json.Marshal (state)
66
+ return string (j)
64
67
}
65
68
```
66
69
Original file line number Diff line number Diff line change @@ -10,11 +10,13 @@ import (
10
10
11
11
func (mws * Controller ) getHealthHandler () webserver.HandlerFunc {
12
12
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 ()
15
15
16
- // Encode and send output
17
- req .WriteJSON (state )
16
+ // Send output
17
+ if len (status ) > 0 {
18
+ req .WriteString (status )
19
+ }
18
20
req .Success ()
19
21
20
22
// Done
Original file line number Diff line number Diff line change @@ -60,8 +60,8 @@ type Options struct {
60
60
Middlewares []webserver.MiddlewareFunc
61
61
}
62
62
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
65
65
66
66
// -----------------------------------------------------------------------------
67
67
Original file line number Diff line number Diff line change 1
1
package metrics_test
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"math/rand"
6
7
"os"
@@ -129,10 +130,13 @@ func TestWebServer(t *testing.T) {
129
130
130
131
// -----------------------------------------------------------------------------
131
132
132
- func healthCallback () interface {} {
133
- return State {
133
+ func healthCallback () string {
134
+ state := State {
134
135
System : "all services running" ,
135
136
}
137
+
138
+ j , _ := json .Marshal (state )
139
+ return string (j )
136
140
}
137
141
138
142
func openBrowser (url string ) {
You can’t perform that action at this time.
0 commit comments