Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1003 Bytes

README.md

File metadata and controls

46 lines (35 loc) · 1003 Bytes

Initializer

Initializer is a simple library to initialize main go service.

go get github.com/worldline-go/initializer

This library customized to use https://github.com/rakunlabs/into

Usage

Default logger is zerolog

var (
	version = "v0.0.0"
	commit  = "-"
	date    = "-"
)

func main() {
	// run the application
	initializer.Init(
		run,
		initializer.WithMsgf("awesome-service version:[%s] commit:[%s] date:[%s]", version, commit, date),
		// if you want to close the application after a certain time without waiting the waitgroup
		// initializer.WithWaitTimeout(0),  // 0 means no timeout as default (time.Duration)
		initializer.WithOptionsLogz(
			logz.WithLevel(zerolog.LevelDebugValue),
		))
}

func run(_ context.Context) error {
	// Do something here.
	log.Info().Msg("Hello World!")

	return fmt.Errorf("something went wrong")
}

Add shutdown function, it will be called when the context is done.

initializer.ShutdownAdd(server.Close, "server")