Skip to content

Instantly share code, notes, and snippets.

@eminetto
Last active September 8, 2022 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eminetto/bb8cd8d3c6f7a348a33925ac62c0e0be to your computer and use it in GitHub Desktop.
Save eminetto/bb8cd8d3c6f7a348a33925ac62c0e0be to your computer and use it in GitHub Desktop.
api.go
const TIMEOUT = 30 * time.Second
//Start a new http server with graceful shutdown and default parameters
func Start(l *logger.Logger, port string, handler http.Handler, options ...ServerOption) error {
srv := &http.Server{
ReadTimeout: TIMEOUT,
WriteTimeout: TIMEOUT,
Addr: ":" + port,
Handler: handler,
}
//detalhes ocultos para este exemplo
}
//WithReadTimeout configure http.Server parameter ReadTimeout
func WithReadTimeout(t time.Duration) ServerOption {
return func(srv *http.Server) {
srv.ReadTimeout = t
}
}
//WithWriteTimeout configure http.Server parameter WriteTimeout
func WithWriteTimeout(t time.Duration) ServerOption {
return func(srv *http.Server) {
srv.WriteTimeout = t
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment