docker

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	ContainerID   string
	ContainerName string
	ServiceName   string // docker-compose service name
	ProjectName   string // docker-compose project name
	Host          string // Container IP in the shared network
	Port          int
	Hostname      string // The hostname to route to this backend
	PathPrefix    string // Optional path prefix
}

Backend represents a proxied service

type Client

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

Client wraps the Docker client for container discovery

func NewClient

func NewClient(networkName, baseDomain string) (*Client, error)

NewClient creates a new Docker client wrapper

func NewClientWithAPI

func NewClientWithAPI(api DockerAPI, networkName, baseDomain string) *Client

NewClientWithAPI creates a new client with a custom DockerAPI implementation This is useful for testing with mock implementations

func (*Client) BaseDomain

func (c *Client) BaseDomain() string

BaseDomain returns the base domain for hostnames

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client

func (*Client) DiscoverBackends

func (c *Client) DiscoverBackends(ctx context.Context) ([]*Backend, error)

DiscoverBackends finds all containers connected to the shared network

func (*Client) DockerClient

func (c *Client) DockerClient() DockerAPI

DockerClient returns the underlying Docker API client (for event watching)

func (*Client) GetBackend

func (c *Client) GetBackend(ctx context.Context, containerID string) (*Backend, error)

GetBackend gets a single backend by container ID

func (*Client) GetProjectBackends

func (c *Client) GetProjectBackends(ctx context.Context, projectName string) ([]*Backend, error)

GetProjectBackends gets all backends for a specific project

func (*Client) NetworkName

func (c *Client) NetworkName() string

NetworkName returns the network name being watched

type ContainerEvent

type ContainerEvent struct {
	Type        EventType
	ContainerID string
}

ContainerEvent represents a container start/stop event

type DockerAPI

type DockerAPI interface {
	ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
	Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error)
	Close() error
}

DockerAPI defines the interface for Docker API operations This interface allows for mocking in tests

type EventType

type EventType int

EventType represents the type of container event

const (
	EventStart EventType = iota
	EventStop
)

type Watcher

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

Watcher watches for container events on the shared network

func NewWatcher

func NewWatcher(client *Client) *Watcher

NewWatcher creates a new container watcher

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context) <-chan ContainerEvent

Watch starts watching for container events and returns a channel of events. Automatically reconnects if the connection is lost.

Jump to

Keyboard shortcuts

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