beego: Index | Files

package grace

import ""

Package grace use to hot reload Description:






 func handler(w http.ResponseWriter, r *http.Request) {

 func main() {
     mux := http.NewServeMux()
     mux.HandleFunc("/hello", handler)

	    err := grace.ListenAndServe("localhost:8080", mux)
     if err != nil {
     log.Println("Server on 8080 stopped")


Package Files

grace.go server.go


const (
    // PreSignal is the position to add filter before signal
    PreSignal = iota
    // PostSignal is the position to add filter after signal
    // StateInit represent the application inited
    // StateRunning represent the application is running
    // StateShuttingDown represent the application is shutting down
    // StateTerminate represent the application is killed


var (

    // DefaultReadTimeOut is the HTTP read timeout
    DefaultReadTimeOut time.Duration
    // DefaultWriteTimeOut is the HTTP Write timeout
    DefaultWriteTimeOut time.Duration
    // DefaultMaxHeaderBytes is the Max HTTP Header size, default is 0, no limit
    DefaultMaxHeaderBytes int
    // DefaultTimeout is the shutdown server's timeout. default is 60s
    DefaultTimeout = grace.DefaultTimeout

func ListenAndServe Uses

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe refer http.ListenAndServe

func ListenAndServeTLS Uses

func ListenAndServeTLS(addr string, certFile string, keyFile string, handler http.Handler) error

ListenAndServeTLS refer http.ListenAndServeTLS

type Server Uses

type Server grace.Server

Server embedded http.Server

func NewServer Uses

func NewServer(addr string, handler http.Handler) (srv *Server)

NewServer returns a new graceServer.

func (*Server) ListenAndServe Uses

func (srv *Server) ListenAndServe() (err error)

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":http" is used.

func (*Server) ListenAndServeMutualTLS Uses

func (srv *Server) ListenAndServeMutualTLS(certFile, keyFile, trustFile string) error

ListenAndServeMutualTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming mutual TLS connections.

func (*Server) ListenAndServeTLS Uses

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

ListenAndServeTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming TLS connections.

Filenames containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.

If srv.Addr is blank, ":https" is used.

func (*Server) RegisterSignalHook Uses

func (srv *Server) RegisterSignalHook(ppFlag int, sig os.Signal, f func()) error

RegisterSignalHook registers a function to be run PreSignal or PostSignal for a given signal.

func (*Server) Serve Uses

func (srv *Server) Serve() (err error)

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.

Package grace imports 4 packages (graph). Updated 2020-11-07. Refresh now. Tools for package owners.