Files
ocis/services/auth-basic/pkg/server/debug/server.go
T

63 lines
1.9 KiB
Go
Raw Normal View History

2019-12-17 17:04:18 +01:00
package debug
import (
"io"
"net/http"
2022-05-04 14:49:59 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
2022-06-20 16:49:06 +02:00
"github.com/owncloud/ocis/v2/services/auth-basic/pkg/config"
2019-12-17 17:04:18 +01:00
)
// Server initializes the debug service and server.
func Server(opts ...Option) (*http.Server, error) {
options := newOptions(opts...)
return debug.NewService(
debug.Logger(options.Logger),
2022-05-02 14:04:28 +02:00
debug.Name(options.Config.Service.Name),
2022-06-13 10:41:14 +02:00
debug.Version(version.GetString()),
2022-05-02 14:04:28 +02:00
debug.Address(options.Config.Debug.Addr),
debug.Token(options.Config.Debug.Token),
debug.Pprof(options.Config.Debug.Pprof),
debug.Zpages(options.Config.Debug.Zpages),
2019-12-17 17:04:18 +01:00
debug.Health(health(options.Config)),
debug.Ready(ready(options.Config)),
2022-05-02 14:04:28 +02:00
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
2019-12-17 17:04:18 +01:00
), nil
}
// 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)
// TODO: check if services are up and running
2019-12-17 17:04:18 +01:00
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
// io.WriteString should not fail but if it does, we want to know.
if err != nil {
2021-02-25 14:14:34 +01:00
panic(err)
}
2019-12-17 17:04:18 +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: check if services are up and running
2019-12-17 17:04:18 +01:00
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
// io.WriteString should not fail but if it does, we want to know.
if err != nil {
2021-02-25 14:14:34 +01:00
panic(err)
}
2019-12-17 17:04:18 +01:00
}
2022-04-13 10:40:24 +02:00
}