benchttp / server

REST API for benchttp.
Other
0 stars 0 forks source link

feat: bootstrap and graceful shutdown #15

Open moreirathomas opened 2 years ago

moreirathomas commented 2 years ago

Description

Breaks main in many methods for a more granular configuration. Offers:

Changes

Refactor cmd/main.

Update golangci-yml:

Notes

Coses #14

moreirathomas commented 2 years ago

The main thing is:

In order to be able to call Server.Shutdown(ctx) and RequestService.Close(), we need to have Server.ListenAndServe to not be blocking.

Server.Shutdown(ctx) must be called while Server.ListenAndServe runs in a goroutine.

Only after Server.ListenAndServe internally gets the interrupt and return http.ErrServerClosed and we can safely exit the program.

My solution was to:

In other words: run launches the server in a thread and returns a way to gracefully stop it from the parent. Any error returned is a fatal error during launch.

Although I agree that shutdown.Handle may be too much.


Also, you raised good points regarding the env vars injections on real world deployment too. We might need to think about that.