Open moreirathomas opened 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:
Server.ListenAndServe
inside a goroutineIn 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.
Description
Breaks
main
in many methods for a more granular configuration. Offers:shutdown
package.config
struct defining the program variable configuration (à la 12 factors app), config is read from file with default being.env
. Accepts one single flag:config
to provide the path to the config file.Changes
Refactor
cmd/main
.Update
golangci-yml
:Notes
Coses #14