Last active
September 8, 2022 23:37
-
-
Save eminetto/bb8cd8d3c6f7a348a33925ac62c0e0be to your computer and use it in GitHub Desktop.
api.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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