Skip to content

rakunlabs/into

Repository files navigation

into

License Go PKG Go Report Card

Helper function to initiate the project easly.

go get github.com/rakunlabs/into

Usage

func main() {
	into.Init(run,
		into.WithMsgf("myservice [%s]", "v0.1.0"),
	)
}

func run(ctx context.Context) error {
	return nil
}

Health Check

You can enable health check endpoint by adding into.WithHealthCheck() option.

into.Init(run,
	into.WithMsgf("myservice [%s]", "v0.1.0"),
	into.WithHealthCheck(),
	into.WithKill(),
)


// 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 --health

Kill Endpoint

You 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

About

main initializer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages