Helper function to initiate the project easly.
go get github.com/rakunlabs/intofunc main() {
into.Init(run,
into.WithMsgf("myservice [%s]", "v0.1.0"),
)
}
func run(ctx context.Context) error {
return nil
}You can enable health check endpoint by adding into.WithHealthCheck() option.
into.Init(run,
into.WithMsgf("myservice [%s]", "v0.1.0"),
into.WithHealthCheck(),
)
// The health check endpoint will be available at /healthz
// Set function to respond to health check requests.
into.HealthCheck = func(ctx context.Context) error {
return errors.New("some problem")
}Call health check from your command line:
go run main.go --healthTo use custom health check endpoint, you can use into.WithHealthCheckCustom() option.
This will not start the health check server, but you can call the health check function directly from your code.
into.Init(run,
into.WithMsgf("myservice [%s]", "v0.1.0"),
into.WithHealthCheck(into.WithHealthCheckCustom()),
)call custom health check endpoint:
go run main.go --health-check http://localhost:18080/healthzYou can enable kill endpoint by adding into.WithKill() option.
into.Init(run,
into.WithMsgf("myservice [%s]", "v0.1.0"),
into.WithHealthCheck(),
into.WithKill(),
)Add extra header check for kill endpoint:
into.KillHeaderCheck = func(h http.Header) bool {
// check for custom header
return h.Get("X-Kill-Secret") == "mysecret"
}
// Or use predefined map check
into.KillHeaderCheckMap(map[string]string{
"X-Kill-Secret": "mysecret",
})Example CURL request to call kill endpoint:
curl -X POST -H "X-Kill-Secret: mysecret" http://localhost:18080/kill