graceful

package
v3.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

README

Package information

Enables graceful shutdown.

Usage

package main

import (
    "github.com/kataras/iris/graceful"
    "github.com/kataras/iris"
    "time"
)

func main() {
    api := iris.New()
    api.Get("/", func(c *iris.Context) {
        c.Write("Welcome to the home page!")
    })

    graceful.Run(":3001", time.Duration(10)*time.Second, api)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogger

func DefaultLogger() *logger.Logger

DefaultLogger returns the logger used by Run, RunWithErr, ListenAndServe, ListenAndServeTLS and Serve. The logger outputs to STDOUT by default.

func Run

func Run(addr string, timeout time.Duration, s *iris.Framework)

Run serves the iris.Handler with graceful shutdown enabled.

timeout is the duration to wait until killing active requests and stopping the server. If timeout is 0, the server never times out. It waits for all active requests to finish. we don't pass an iris.RequestHandler , because we need iris.station.server to be setted in order the station.Close() to work

func RunWithErr

func RunWithErr(addr string, timeout time.Duration, s *iris.Framework) error

RunWithErr is an alternative version of Run function which can return error.

Unlike Run this version will not exit the program if an error is encountered but will return it instead.

Types

type Server

type Server struct {
	*iris.Server

	// Timeout is the duration to allow outstanding requests to survive
	// before forcefully terminating them.
	Timeout time.Duration

	// Limit the number of outstanding requests
	ListenLimit int

	// BeforeShutdown is an optional callback function that is called
	// before the listener is closed.
	BeforeShutdown func()

	// ShutdownInitiated is an optional callback function that is called
	// when shutdown is initiated. It can be used to notify the client
	// side of long lived connections (e.g. websockets) to reconnect.
	ShutdownInitiated func()

	// NoSignalHandling prevents graceful from automatically shutting down
	// on SIGINT and SIGTERM. If set to true, you must shut down the server
	// manually with Stop().
	NoSignalHandling bool

	// Logger used to notify of errors on startup and on stop.
	Logger *logger.Logger

	// Interrupted is true if the server is handling a SIGINT or SIGTERM
	// signal and is thus shutting down.
	Interrupted bool
	// contains filtered or unexported fields
}

Server wraps an iris.Server with graceful connection handling. It may be used directly in the same way as iris.Server, or may be constructed with the global functions in this package.

func (*Server) Stop

func (srv *Server) Stop(timeout time.Duration)

Stop instructs the type to halt operations and close the stop channel when it is finished.

timeout is grace period for which to wait before shutting down the server. The timeout value passed here will override the timeout given when constructing the server, as this is an explicit command to stop the server.

func (*Server) StopChan

func (srv *Server) StopChan() <-chan struct{}

StopChan gets the stop channel which will block until stopping has completed, at which point it is closed. Callers should never close the stop channel.

Jump to

Keyboard shortcuts

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