Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit f0dc25b

Browse files
committed
Health callback change.
1 parent 896c6c5 commit f0dc25b

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

handlers.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010

1111
func (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

metrics.go

+2-2
Original file line numberDiff line numberDiff 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

metrics_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metrics_test
22

33
import (
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

138142
func openBrowser(url string) {

0 commit comments

Comments
 (0)