service

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 Event

type Event struct {
	Time    time.Time
	Message string
}

Event records a state change or notable occurrence in a service's lifetime.

type Option

type Option func(opts *options)

Option is a functional option for configuring a service.

func AdmissionOption

func AdmissionOption(admission admission.Admission) Option

AdmissionOption sets the admission controller that filters connections by source address.

func ClosersOption added in v0.28.1

func ClosersOption(closers ...io.Closer) Option

ClosersOption registers io.Closers that are called on service shutdown.

func LabelsOption added in v0.28.1

func LabelsOption(labels map[string]string) Option

LabelsOption sets the static labels attached to the service's records and logs.

func LoggerOption

func LoggerOption(logger logger.Logger) Option

LoggerOption sets the logger for the service. If not provided, a no-op logger is used.

func ObserverOption

func ObserverOption(observer observer.Observer) Option

ObserverOption sets the observer that receives service state and stats events.

func ObserverPeriodOption added in v0.0.3

func ObserverPeriodOption(period time.Duration) Option

ObserverPeriodOption sets the interval at which stats are reported to the observer. Defaults to 5 seconds with a minimum of 1 second.

func PostDownOption

func PostDownOption(cmds []string) Option

PostDownOption sets shell commands to run after the service stops.

func PostUpOption

func PostUpOption(cmds []string) Option

PostUpOption sets shell commands to run after the service starts listening.

func PreDownOption

func PreDownOption(cmds []string) Option

PreDownOption sets shell commands to run before the service stops.

func PreUpOption

func PreUpOption(cmds []string) Option

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

func StatsOption(stats stats.Stats) Option

StatsOption sets the traffic statistics collector for the service.

type ServiceEvent

type ServiceEvent struct {
	Kind    string
	Service string
	State   State
	Msg     string
}

ServiceEvent is an observer event representing a service state change.

func (ServiceEvent) Type

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

func (p *Status) CreateTime() time.Time

CreateTime returns the time at which the service was created.

func (*Status) Events

func (p *Status) Events() []Event

Events returns a snapshot of the recent event log. The returned slice is safe to modify without affecting the internal state.

func (*Status) LastError added in v0.28.1

func (p *Status) LastError() error

LastError returns the last accept/bind error that caused the service to enter StateFailed. Returns nil if the service never entered the failed state.

func (*Status) State

func (p *Status) State() State

State returns the current service state.

func (*Status) Stats

func (p *Status) Stats() stats.Stats

Stats returns the traffic statistics for the service. It safely handles nil receivers by returning nil.

Jump to

Keyboard shortcuts

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