Files
ocis/graph/pkg/server/debug/server.go
T

55 lines
1.5 KiB
Go
Raw Normal View History

2019-12-04 17:15:11 +01:00
package debug
import (
"io"
"net/http"
2021-02-04 11:46:32 +01:00
"github.com/owncloud/ocis/graph/pkg/config"
2021-02-16 13:55:34 +01:00
"github.com/owncloud/ocis/ocis-pkg/service/debug"
2021-10-05 12:39:31 +02:00
"github.com/owncloud/ocis/ocis-pkg/version"
2019-12-04 17:15:11 +01:00
)
2019-12-06 13:14:21 +01:00
// Server initializes the debug service and server.
2019-12-04 17:15:11 +01:00
func Server(opts ...Option) (*http.Server, error) {
options := newOptions(opts...)
2019-12-06 13:14:21 +01:00
return debug.NewService(
debug.Logger(options.Logger),
debug.Name("graph"),
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.Config)),
debug.Ready(ready(options.Config)),
), nil
}
2019-12-04 17:15:11 +01:00
2019-12-06 13:14:21 +01:00
// health implements the health check.
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
2019-12-04 17:15:11 +01:00
2019-12-06 13:14:21 +01:00
// TODO(tboerger): check if services are up and running
2019-12-04 17:15:11 +01:00
2021-02-25 15:53:46 +01:00
if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil {
panic(err)
}
2019-12-04 17:15:11 +01:00
}
2019-12-06 13:14:21 +01:00
}
2019-12-04 17:15:11 +01:00
2019-12-06 13:14:21 +01:00
// ready implements the ready check.
func ready(cfg *config.Config) 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
2019-12-04 17:15:11 +01:00
2021-02-25 15:53:46 +01:00
if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil {
panic(err)
}
2019-12-06 13:14:21 +01:00
}
2019-12-04 17:15:11 +01:00
}