listener

package module
v0.0.0-...-c7c2ec3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: ISC Imports: 11 Imported by: 8

README

Deprecated!

Please use hserve instead.


listener

A small library to provide TCP+Unix listener functions as well as graceful shutdowns.

Usage

server := http.Server{
	Addr:    "unix:///tmp/server.sock",
	Handler: handler,
}

// This function will block until SIGINT is received or HTTP servers error out.
if err := listener.HTTPListenAndServe(&server); err != nil {
	log.Fatalln("Failed to serve HTTP:", err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultListenConfig = &net.ListenConfig{}

DefaultListenConfig is the default ListenConfig used for Listen().

View Source
var HTTPShutdownTimeout = 5 * time.Second

HTTPShutdownTimeout is the timeout to wait when shutting down HTTP.

Functions

func HTTPListenAndServe

func HTTPListenAndServe(address string, handler http.Handler) error

HTTPListenAndServe listens and serves HTTP until a SIGINT is received.

func HTTPListenAndServeCtx

func HTTPListenAndServeCtx(ctx context.Context, server *http.Server) error

HTTPListenAndServeCtx listens to the address set in http.Server and serves HTTP. It gracefully exits if the given ctx expires.

func Listen

func Listen(address string) (net.Listener, error)

Listen calls ListenWithConfig with the DefaultListenConfig.

func ListenWithConfig

func ListenWithConfig(config *net.ListenConfig, address string) (net.Listener, error)

ListenWithConfig listens for incoming connections using the given address string. The address can be formatted as such:

127.0.0.1:29485 (implicitly tcp)
tcp://127.0.0.1:29485
tcp4://127.0.0.1:29485
unix:///tmp/path/to/socket.sock (will be automatically cleaned up)
unixpacket:///tmp/path/to/socket.sock (same as unix)

func MustHTTPListenAndServe

func MustHTTPListenAndServe(address string, handler http.Handler)

MustHTTPListenAndServe is HTTPListenAndServe that log.Fatals on an error.

func MustHTTPListenAndServeCtx

func MustHTTPListenAndServeCtx(ctx context.Context, server *http.Server)

MustHTTPListenAndServeCtx is HTTPListenAndServeCtx that log.Fatals on an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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