Documentation
¶
Overview ¶
grace provides for graceful restart for go http servers. There are 2 parts to graceful restarts 1. Share listening sockets (this is done via socketmaster binary) 2. Close listener gracefully (via graceful)
Index ¶
- func GetListenPort(hport string) string
- func Listen(hport string) (net.Listener, error)
- func Run(addr string, timeout time.Duration, n http.Handler)
- func RunWithErr(addr string, timeout time.Duration, n http.Handler) error
- func Serve(hport string, handler http.Handler) error
- func ServeWithConfig(hport string, config Config, handler http.Handler) error
- func ServerFastHTTP(hport string, handler fasthttp.RequestHandler) error
- type Config
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetListenPort ¶
GetListenPort applications need some way to access the port TODO: this method will work only after grace.Serve is called.
func RunWithErr ¶
RunWithErr exports RunWithErr from grace package
func Serve ¶
Serve start serving on hport. If running via socketmaster, the hport argument is ignored. Also, if a port was specified via -p, it takes precedence on hport
Example ¶
package main
import (
"log"
"net/http"
grace "github.com/b3bas/grace"
)
func main() {
http.HandleFunc("/foo/bar", foobarHandler)
log.Fatal(grace.Serve(":9000", nil))
}
func foobarHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("foobar"))
}
Output:
func ServeWithConfig ¶
ServeWithConfig serve using package config
func ServerFastHTTP ¶
func ServerFastHTTP(hport string, handler fasthttp.RequestHandler) error
ServerFastHTTP use fasthttp server
Types ¶
Click to show internal directories.
Click to hide internal directories.