shutdown

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LazyShutdown

type LazyShutdown struct {
	// contains filtered or unexported fields
}

LazyShutdown basically provides a context and HTTP server helpers which allow shutdown after inactivity. This can be useful for hosting services whose running binary should naturally evict itself after some time.

func New

func New(wait time.Duration) *LazyShutdown

New builds a new LazyShutdown.

func (*LazyShutdown) Done

func (ls *LazyShutdown) Done() <-chan struct{}

Done returns a channel which closes when this LazyShutdown has timed out.

func (*LazyShutdown) Err

func (ls *LazyShutdown) Err(err error)

Err shuts down when an error is passed here. This is useful for ListenAndServe, which always returns an error.

func (*LazyShutdown) IsDone

func (ls *LazyShutdown) IsDone() bool

IsDone immediately returns whether this is done.

func (*LazyShutdown) Lock

func (ls *LazyShutdown) Lock()

Lock prevents this LazyShutdown from firing. This acts like a `sync.RWMutex`.

func (*LazyShutdown) Reason

func (ls *LazyShutdown) Reason() error

Reason returns any previously recorded shutdown error via Err().

func (*LazyShutdown) Reset

func (ls *LazyShutdown) Reset()

Reset resets the timer on this LazyShutdown only if is free to fire.

func (*LazyShutdown) Serve

func (ls *LazyShutdown) Serve(addr string, handler http.Handler) error

Serve servers HTTP until the LazyShutdown shuts down. Active requests do not explicitly cause it to stay alive, only requests wrapped by ServeWrap.

func (*LazyShutdown) ServeWrap

func (ls *LazyShutdown) ServeWrap(addr string, handler http.Handler) error

ServeWrap is as Serve, but ensures that _all_ requests handled by this server prevent shutdown.

func (*LazyShutdown) Unlock

func (ls *LazyShutdown) Unlock()

Unlock allows this LazyShutdown to fire. It is a fatal error to unlock more than lock.

func (*LazyShutdown) WaitDuration

func (ls *LazyShutdown) WaitDuration() time.Duration

WaitDuration returns the original setup duration.

func (*LazyShutdown) Wrap

func (ls *LazyShutdown) Wrap(h http.Handler) http.Handler

Wrap wraps a http.Handler such that this LazyShutdown will not close while it is active.

func (*LazyShutdown) WrapFunc

func (ls *LazyShutdown) WrapFunc(fn http.HandlerFunc) http.HandlerFunc

WrapFunc wraps a http.HandlerFunc such that this LazyShutdown will not close while it is active.

Jump to

Keyboard shortcuts

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