Documentation
¶
Overview ¶
Package anyhttp has helpers to serve http from unix sockets and systemd socket activated fds
Index ¶
Constants ¶
const StartFD = 3
StartFD is the starting file descriptor number
Variables ¶
var DefaultSysdConfig = SysdConfig{ CheckPID: true, UnsetEnv: true, }
DefaultSysdConfig has the default values for SysdConfig
var DefaultUnixSocketConfig = UnixSocketConfig{ SocketMode: 0666, RemoveExisting: true, }
DefaultUnixSocketConfig has defaults for UnixSocketConfig
Functions ¶
func ListenAndServe ¶
ListenAndServe is the drop-in replacement for `http.ListenAndServe`. Supports unix and systemd sockets in addition
func ListenAndServeTLS ¶ added in v0.5.0
func UnsetSystemdListenVars ¶
func UnsetSystemdListenVars()
UnsetSystemdListenVars unsets the LISTEN* environment variables so they are not passed to any child processes
Types ¶
type AddressType ¶ added in v0.3.0
type AddressType string
AddressType of the address passed
var ( // UnixSocket - address is a unix socket, e.g. unix?path=/run/foo.sock UnixSocket AddressType = "UnixSocket" // SystemdFD - address is a systemd fd, e.g. sysd?name=myapp.socket SystemdFD AddressType = "SystemdFD" // TCP - address is a TCP address, e.g. :1234 TCP AddressType = "TCP" // Unknown - address is not recognized Unknown AddressType = "Unknown" )
func GetListener ¶
GetListener is low level function for use with non-http servers. e.g. tcp, smtp Caller should handle idle timeout if needed
type ServerCtx ¶ added in v0.5.0
type ServerCtx struct {
AddressType AddressType
Listener net.Listener
Server *http.Server
Idler idle.Idler
Done <-chan error
UnixSocketConfig *UnixSocketConfig
SysdConfig *SysdConfig
}
type SysdConfig ¶
type SysdConfig struct {
// Integer value starting at 0. Either index or name is required
FDIndex *int
// Name configured via FileDescriptorName or the default socket file name. Either index or name is required
FDName *string
// Check process PID matches LISTEN_PID
CheckPID bool
// Unsets the LISTEN* environment variables, so they don't get passed to any child processes
UnsetEnv bool
// Shutdown http server if no requests received for below timeout
IdleTimeout *time.Duration
}
SysdConfig has the configuration for the socket activated fd
func NewSysDConfigWithFDIdx ¶
func NewSysDConfigWithFDIdx(fdIdx int) SysdConfig
NewSysDConfigWithFDIdx creates SysdConfig with defaults and fdIdx
func NewSysDConfigWithFDName ¶
func NewSysDConfigWithFDName(fdName string) SysdConfig
NewSysDConfigWithFDName creates SysdConfig with defaults and fdName
func (*SysdConfig) GetListener ¶
func (s *SysdConfig) GetListener() (net.Listener, error)
GetListener returns the FileListener created with socketed activated fd
type UnixSocketConfig ¶
type UnixSocketConfig struct {
// Absolute or relative path of socket, e.g. /run/app.sock
SocketPath string
// Socket file permission
SocketMode fs.FileMode
// Whether to delete existing socket before creating new one
RemoveExisting bool
}
UnixSocketConfig has the configuration for Unix socket
func NewUnixSocketConfig ¶
func NewUnixSocketConfig(socketPath string) UnixSocketConfig
NewUnixSocketConfig creates a UnixSocketConfig with the default values and the socketPath passed
func (*UnixSocketConfig) GetListener ¶
func (u *UnixSocketConfig) GetListener() (net.Listener, error)
GetListener returns the unix socket listener
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
idle_server_shutdown
command
|
|
|
simple
command
|
|
|
Package idle helps to gracefully shutdown idle (typically http) servers
|
Package idle helps to gracefully shutdown idle (typically http) servers |