Documentation ¶
Overview ¶
Example ¶
package main import ( "io" "net/http" "time" "github.com/diamondburned/gracehttp" ) const addr = "unix:///tmp/gracehttp-example.sock" func main() { // ListenAndServeAsync will only block until the listener is being served. server := gracehttp.ListenAndServeAsync(addr, http.HandlerFunc(handle)) defer server.ShutdownTimeout(5 * time.Second) time.Sleep(time.Second) } func handle(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello, 世界") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAddr ¶
ListenAddr parses the given address and returns either a TCP or Unix listener. Below lists acceptable formats.
unixpacket://relative/path/to.socket unix:///path/to.socket /path/to.socket http://address tcp4://address tcp6://address tcp://address address
func ListenAddrCfg ¶
ListenAddrCfg is ListenAddr with additional parameters.
func WaitForInterrupt ¶
WaitForInterrupt blocks until an interrupt signal is received.
Types ¶
type Server ¶
Server is the wrapper around a regular net/http server. It is not thread-safe, and must never be shared across goroutines.
func ListenAndServeAsync ¶
ListenAndServeAsync listens and serves the given address. The returned server can be used to gracefully shut down the server.
func MustServer ¶
MustServer creates a new server and panics if it fails.
func NewCustomServer ¶
NewCustomServer creates a new graceful server instance from the given configs. If h2 is nil, then HTTP2 is not forced.
func (*Server) ListenAndServe ¶
ListenAndServe listens to and serves the server's address. The context is used for timing out the initial listen.
func (*Server) ListenAndServeAsync ¶
ListenAndServeAsync listens to the server's address and serves in a background goroutine. The context is used for timing out the initial listen.