-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
61 lines (51 loc) · 1.65 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package debug
import (
"io"
"net/http"
"github.com/cernbox/ocis-canary/pkg/version"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/service/debug"
)
// Server initializes the debug service and server.
func Server(opts ...Option) (*http.Server, error) {
options := newOptions(opts...)
return debug.NewService(
debug.Logger(options.Logger),
debug.Name(options.Name),
debug.Version(version.String),
debug.Address(options.Config.Debug.Addr),
debug.Token(options.Config.Debug.Token),
debug.Pprof(options.Config.Debug.Pprof),
debug.Zpages(options.Config.Debug.Zpages),
debug.Health(health(options.Logger)),
debug.Ready(ready(options.Logger)),
), nil
}
// health implements the health check.
func health(logger log.Logger) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
// TODO(tboerger): check if services are up and running
if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil {
logger.Error().
Err(err).
Str("request", "health").
Msg("Failed to write response")
}
}
}
// ready implements the ready check.
func ready(logger log.Logger) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
// TODO(tboerger): check if services are up and running
if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil {
logger.Error().
Err(err).
Str("request", "ready").
Msg("Failed to write response")
}
}
}