sleepingd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(format string, args ...interface{})

func LogError

func LogError(err error)

func Main

func Main(opts *Options) error

func Must

func Must(err error)

Types

type DeadMansSwitch

type DeadMansSwitch struct {
	DelayCh  chan<- struct{}
	ExpireCh <-chan struct{}
	Expired  bool
}

DeadMansSwitch is a struct used for getting automatically notified some time after a process stops sending events. See GetDeadMansSwitch for more explanation of usage.

func NewDeadMansSwitch

func NewDeadMansSwitch(timeout time.Duration) *DeadMansSwitch

NewDeadMansSwitch returns a DeadMansSwitch struct. This struct contains two channels. The ExpireCh will receive an event automatically after the provided timeout. However, at any time you can send an event to the DelayCh to re-set this timeout to be from the current time rather than from when the NewDeadMansSwitch was returned. In other words, this lets you get notified automatically some time after a process stops sending events. To help in avoiding race conditions, the field Expired is set from false to true immediately *before* an event is sent to the ExpireCh.

type Options

type Options struct {
	Command        string `validate:"nonzero"`
	TimeoutSeconds int    `validate:"min=1"`
	CommandPort    int    `validate:"min=1"`
	ListenPort     int    `validate:"min=1"`
	ListenHost     string `validate:"nonzero"`
}

type Proxy

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

Proxy is a struct returned by NewProxy, that represents a running proxy server. It can be used to stop the server by calling Close.

func NewProxy

func NewProxy(opts *ProxyOptions) (*Proxy, error)

NewProxy creates and starts a TCP or UDP server that will transparently proxy TCP/UDP traffic to an upstream address, see ProxyOptions for the options. An instance of Proxy is returned which can be used to stop the server later.

func (*Proxy) Close

func (p *Proxy) Close() error

type ProxyOptions

type ProxyOptions struct {
	// Protocol is either "tcp" or "udp"
	Protocol string
	// ListenAddr is the address the proxy server will listen for
	// incoming TCP/UDP traffic on, e.g. "127.0.0.1:80"
	ListenAddr string
	// UpstreamAddr is the upstream address the proxy will proxy
	// TCP/UDP traffic to, e.g. "127.0.0.1:8080"
	UpstreamAddr string
	// NewConnectionCallback is a function of no arguments,
	// optional. If provided, then it is called synchronously when
	// a new connection is accepted, but before the connection is
	// proxied to the upstream address. This could be used to
	// track metrics on incoming connections, or to ensure that
	// the upstream is available before traffic is proxied to it.
	NewConnectionCallback func()
}

ProxyOptions is used to configure NewProxy, which see for documentation. All fields are required except NewConnectionCallback.

type SubprocessManager

type SubprocessManager struct {
	Command                []string
	TerminationGracePeriod time.Duration
	EnsureListeningTimeout time.Duration
	// contains filtered or unexported fields
}

func (*SubprocessManager) EnsureListening

func (sm *SubprocessManager) EnsureListening(port int) error

func (*SubprocessManager) EnsureStarted

func (sm *SubprocessManager) EnsureStarted() error

func (*SubprocessManager) EnsureStopped

func (sm *SubprocessManager) EnsureStopped() error

Jump to

Keyboard shortcuts

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