Skip to content

Instantly share code, notes, and snippets.

Last active September 8, 2022 23:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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