grace

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package grace use to hot reload Description: http://grisha.org/blog/2014/06/03/graceful-restart-in-golang/

Usage:

import(

  "log"
	 "net/http"
	 "os"

  "github.com/astaxie/beego/grace"

)

 func server(w http.ResponseWriter, r *http.Request) {
	  w.Write([]byte("WORLD!"))
 }

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

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

Index

Constants

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

Variables

View Source
var (

	// DefaultMaxHeaderBytes is the Max HTTP Herder size, default is 0, no limit
	DefaultMaxHeaderBytes int
	// DefaultTimeout is the shutdown server's timeout. default is 60s
	DefaultTimeout = 60 * time.Second
)

Functions

func ListenAndServe

func ListenAndServe(addr string, server *http.Server, logger logs.Logger) error

ListenAndServe refer http.ListenAndServe

func ListenAndServeTLS

func ListenAndServeTLS(addr string, certFile string, keyFile string, server *http.Server, logger logs.Logger) error

ListenAndServeTLS refer http.ListenAndServeTLS

Types

type Server

type Server struct {
	*http.Server

	GraceListener net.Listener
	SignalHooks   map[int]map[os.Signal][]func()

	Network string
	// contains filtered or unexported fields
}

Server embedded http.Server

func NewServer

func NewServer(addr string, server *http.Server, logger logs.Logger) (srv *Server)

NewServer returns a new graceServer.

func (*Server) ListenAndServe

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) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) (err 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) Serve

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL