Documentation
¶
Overview ¶
Package service implements the core service.Service interface, binding a listener.Listener and a handler.Handler into a runnable proxy service that accepts inbound connections and forwards traffic through a proxy chain.
Index ¶
- Constants
- func NewService(name string, ln listener.Listener, h handler.Handler, opts ...Option) service.Service
- type Event
- type Option
- func AdmissionOption(admission admission.Admission) Option
- func ClosersOption(closers ...io.Closer) Option
- func LabelsOption(labels map[string]string) Option
- func LoggerOption(logger logger.Logger) Option
- func ObserverOption(observer observer.Observer) Option
- func ObserverPeriodOption(period time.Duration) Option
- func PostDownOption(cmds []string) Option
- func PostUpOption(cmds []string) Option
- func PreDownOption(cmds []string) Option
- func PreUpOption(cmds []string) Option
- func RecordersOption(recorders ...recorder.RecorderObject) Option
- func StatsOption(stats stats.Stats) Option
- type ServiceEvent
- type State
- type Status
Constants ¶
const MaxEventSize = 20
MaxEventSize is the maximum number of events retained in a Status event log. When the log is full, the oldest event is discarded.
Variables ¶
This section is empty.
Functions ¶
func NewService ¶
func NewService(name string, ln listener.Listener, h handler.Handler, opts ...Option) service.Service
NewService creates a new service that binds the given listener and handler. The service is registered in the running state and pre-up commands are executed immediately. Call [Serve] to start accepting connections.
Types ¶
type Option ¶
type Option func(opts *options)
Option is a functional option for configuring a service.
func AdmissionOption ¶
AdmissionOption sets the admission controller that filters connections by source address.
func ClosersOption ¶ added in v0.28.1
ClosersOption registers io.Closers that are called on service shutdown.
func LabelsOption ¶ added in v0.28.1
LabelsOption sets the static labels attached to the service's records and logs.
func LoggerOption ¶
LoggerOption sets the logger for the service. If not provided, a no-op logger is used.
func ObserverOption ¶
ObserverOption sets the observer that receives service state and stats events.
func ObserverPeriodOption ¶ added in v0.0.3
ObserverPeriodOption sets the interval at which stats are reported to the observer. Defaults to 5 seconds with a minimum of 1 second.
func PostDownOption ¶
PostDownOption sets shell commands to run after the service stops.
func PostUpOption ¶
PostUpOption sets shell commands to run after the service starts listening.
func PreDownOption ¶
PreDownOption sets shell commands to run before the service stops.
func PreUpOption ¶
PreUpOption sets shell commands to run before the service starts.
func RecordersOption ¶
func RecordersOption(recorders ...recorder.RecorderObject) Option
RecordersOption sets the traffic recorders for the service.
func StatsOption ¶
StatsOption sets the traffic statistics collector for the service.
type ServiceEvent ¶
ServiceEvent is an observer event representing a service state change.
func (ServiceEvent) Type ¶
func (ServiceEvent) Type() observer.EventType
Type returns the observer event type for service events.
type State ¶
type State string
State represents the operational state of a service.
const ( // StateRunning indicates the service has been created but is not yet accepting. StateRunning State = "running" // StateReady indicates the service is actively accepting connections. StateReady State = "ready" // StateFailed indicates the service accept loop encountered a temporary error. StateFailed State = "failed" // StateClosed indicates the service has been shut down. StateClosed State = "closed" )
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status tracks the runtime state, event log, and traffic statistics of a service.
func (*Status) CreateTime ¶
CreateTime returns the time at which the service was created.
func (*Status) Events ¶
Events returns a snapshot of the recent event log. The returned slice is safe to modify without affecting the internal state.