Documentation ¶
Index ¶
- func ListenAndServe(h *http.Server) error
- func ListenAndServeTLS(h *http.Server, certFile, keyFile string) error
- func Run(addr string, handler http.Handler) error
- type GracefulServer
- func (s *GracefulServer) ListenAndServe(srv *http.Server) error
- func (s *GracefulServer) ListenAndServeTLS(srv *http.Server, certFile, keyFile string) error
- func (s *GracefulServer) Run(addr string, handler http.Handler) error
- func (s *GracefulServer) Serve(srv *http.Server, listener net.Listener) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
Helper function that does the same as GracefulServer.ListenAndServe, automatically shutting down whenever a SIGINT or SIGTERM is sent to the process.
func ListenAndServeTLS ¶
Helper function that does the same as GracefulServer.ListenAndServeTLS, automatically shutting down whenever a SIGINT or SIGTERM is sent to the process.
Types ¶
type GracefulServer ¶
type GracefulServer struct { // The shutdown channel. Send on this channel to shut down the server. // Note that when the send finishes, the server may not yet be shut down - the // call to Serve() will return when the shutdown is complete. Shutdown chan struct{} // Time between when the shutdown has been signalled and all remaining open // connections are forcefully closed. A value of 0 represents no timeout, and // that the server should wait until all open connections are closed before // returning. Timeout time.Duration }
func NewServer ¶
func NewServer() *GracefulServer
Create a new instance of GracefulServer with a default timeout of 10 seconds.
func (*GracefulServer) ListenAndServe ¶
func (s *GracefulServer) ListenAndServe(srv *http.Server) error
ListenAndServe is equivalent to http.Server.ListenAndServe with graceful shutdown enabled.
func (*GracefulServer) ListenAndServeTLS ¶
func (s *GracefulServer) ListenAndServeTLS(srv *http.Server, certFile, keyFile string) error
ListenAndServeTLS is equivalent to http.Server.ListenAndServeTLS with graceful shutdown enabled.
func (*GracefulServer) Run ¶
func (s *GracefulServer) Run(addr string, handler http.Handler) error
Run serves the given http.Handler with graceful shutdown enabled.
func (*GracefulServer) Serve ¶
Serve is equivalent to http.Server.Serve with graceful shutdown enabled.
This function will return when the server has been properly shut down and all open connections have been closed, or, if the timeout expires, when all remaining open connections have been forcefully closed.