api.go
This file contains 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