zerodt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2017 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ZeroDT

GoDoc Build Status Go Report Status

Package ZeroDT offers a zero downtime restart and a graceful shutdown for HTTP servers. Key features:

  • supported both stateless and stateful servers
  • compatible with systemd's socket activation
  • based on out-of-the-box http.Server
  • work with any number of servers
  • not a framework

Example

The simplest way to use ZeroDT is to pass your http.Server to the zerodt.NewApp function and call zerodt.ListenAndServe for an object it returns:

package main

import (
    "io"
    "net/http"
    "time"

    "github.com/acronis/zerodt"
)

func hello(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "Hello world!")
}

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

    a := zerodt.NewApp(&http.Server{Addr: ":8081", Handler: mux})
    a.ListenAndServe()
}

Adopting your HTTP server to use as systemd's service

Under construction

Documentation

Overview

Package zerodt offers a zero downtime restart and a graceful shutdown for HTTP servers.

The simplest way to use ZeroDT is to pass your http.Server to the NewApp() function and call ListenAndServe() for an object it returns:

package main

import (
	"io"
	"net/http"
	"time"

	"github.com/acronis/zerodt"
)

func hello(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "Hello world!")
}

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

	a := zerodt.NewApp(&http.Server{Addr: ":8081", Handler: mux})
	a.ListenAndServe()
}

For more details visit https://github.com/acronis/zerodt

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l StdLogger)

SetLogger allows to set a different logger that is compatible with StdLogger interface. Tested with stdlib logger:

log.New(os.Stderr, "", log.LstdFlags)

And sirupsen/logrus:

logrus.StandardLogger()

Types

type App

type App struct {
	PreServeFn         func(inherited bool) error
	CompleteShutdownFn func()
	PreParentExitFn    func()
	// contains filtered or unexported fields
}

App specifies functions to control passed HTTP servers.

func NewApp

func NewApp(servers ...*http.Server) *App

NewApp returns a new instance of App.

func (*App) ListenAndServe added in v0.1.1

func (a *App) ListenAndServe() error

ListenAndServe calls ListenAndServe for all servers and returns first error if happens or nil.

func (*App) SetWaitChildTimeout added in v0.1.1

func (a *App) SetWaitChildTimeout(d time.Duration)

SetWaitChildTimeout does nothing.

func (*App) SetWaitParentShutdownTimeout added in v0.1.1

func (a *App) SetWaitParentShutdownTimeout(d time.Duration)

SetWaitParentShutdownTimeout does nothing.

func (*App) Shutdown added in v0.1.1

func (a *App) Shutdown() error

Shutdown calls Shutdown for all server and returns first error if happens or nil.

type StdLogger

type StdLogger interface {
	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})
}

StdLogger is an interface for stdlib logger also compatible with logrus

Directories

Path Synopsis
examples
test command

Jump to

Keyboard shortcuts

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