listener

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 10 Imported by: 0

README

zero-downtime-listener

A simple package to create zero downtime listener.

Usage

Standard http package:

listeners, err := listener.NewListeners([]string{":8080"})
if err != nil {
    log.Fatalln(err)
}
http.Serve(listeners[0], nil)
listener.Wait() //Wait for the accepted connections running complete

Gin framework:

listeners, err := listener.NewListeners([]string{":8080"})
if err != nil {
    log.Fatalln(err)
}

router := gin.Default()
router.GET("/", func(c *gin.Context) {
    c.String(http.StatusOK, "this is a test")
})
router.RunListener(listeners[0])
listener.Wait() //Wait for the accepted connections running complete

Close listeners:

listener.Close()

Restart command:

kill -HUP PID

Thanks:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SigChildSuccess   = syscall.Signal(12)
	SigRequestRestart = syscall.SIGHUP

	ForkTimeout    = time.Second * 10
	ForkTimeoutErr = errors.New("forking timeout")
)

Functions

func Close

func Close()

func Wait

func Wait()

Types

type Connection

type Connection struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close() error

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

func NewListeners

func NewListeners(addresses ...string) ([]*Listener, error)

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

func (*Listener) Close

func (l *Listener) Close() error

Jump to

Keyboard shortcuts

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