Documentation
¶
Index ¶
- Variables
- func Run(ctx context.Context, callback Callback, opts ...Option) error
- type Callback
- type Container
- type DockerClient
- type Filter
- type Network
- type Option
- func WithAutoReconnect(minDelay, maxDelay time.Duration, maxRetries int) Option
- func WithDebounce(d time.Duration) Option
- func WithDockerClient(client DockerClient) Option
- func WithFilter(filter Filter) Option
- func WithMaxDebounceTime(d time.Duration) Option
- func WithMaxIdleTime(d time.Duration) Option
- type Port
Constants ¶
This section is empty.
Variables ¶
var Log func(msg string, keysAndValues ...any) = slog.Debug
Log is the logging function used by the library. It takes a message and optional key-value pairs for structured logging. Defaults to slog.Debug but can be overridden.
Functions ¶
Types ¶
type Callback ¶
type Callback func(containers []Container)
Callback is invoked when the set of matching containers changes.
type Container ¶
type Container struct {
ID string // Full container ID
Name string // Container name (without leading slash)
Image string // Image name (e.g., "nginx:latest")
State string // Container state (e.g., "running", "exited", "paused")
Labels map[string]string // Container labels
Networks []Network // All connected networks
Ports []Port // Published port mappings
}
Container represents a Docker container's relevant state.
type DockerClient ¶
type DockerClient interface {
// Events returns a channel of Docker events and a channel of errors.
Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error)
// ContainerList returns a list of containers.
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
// ContainerInspect returns detailed information about a container.
ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
}
DockerClient is the interface required from the Docker SDK. This is a subset of client.APIClient for easier testing and custom client injection.
type Filter ¶
Filter is a function that determines whether a container should be included.
func All ¶
All returns a filter that matches if all given filters match (AND). Returns true if the filter list is empty.
func Any ¶
Any returns a filter that matches if any given filter matches (OR). Returns false if the filter list is empty.
func LabelEquals ¶
LabelEquals returns a filter that matches containers where the given label equals the given value.
func LabelExists ¶
LabelExists returns a filter that matches containers with the given label key.
func StateEquals ¶
StateEquals returns a filter that matches containers in the given state.
type Network ¶
type Network struct {
Name string // Network name
ID string // Network ID
IPAddress string // IPv4 address on this network
IP6Address string // IPv6 address on this network (if any)
Gateway string // Gateway for this network
Aliases []string // Container's DNS aliases on this network
}
Network represents a container's connection to a Docker network.
type Option ¶
type Option func(*config)
Option configures the monitor.
func WithAutoReconnect ¶
WithAutoReconnect enables automatic reconnection on event stream errors. Uses exponential backoff starting at minDelay, doubling up to maxDelay. maxRetries of 0 means retry forever, otherwise stop after that many attempts. On successful reconnection, containers will be refreshed.
func WithDebounce ¶
WithDebounce sets the debounce duration for coalescing rapid events. Default is 100ms.
func WithDockerClient ¶
func WithDockerClient(client DockerClient) Option
WithDockerClient sets a custom Docker client. If not provided, a client will be created using default settings.
func WithFilter ¶
WithFilter sets the filter for selecting containers. Use All() or Any() to combine multiple filters.
func WithMaxDebounceTime ¶
WithMaxDebounceTime sets the maximum time to wait when debouncing. This prevents indefinite delays when events keep arriving. Default is 5 seconds.
func WithMaxIdleTime ¶
WithMaxIdleTime sets the maximum time to wait before polling for changes. Default is 30 seconds.