utils

package
v0.0.0-...-8f96094 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidLogLevels = map[string]bool{
	"debug": true,
	"info":  true,
	"warn":  true,
	"error": true,
}

ValidLogLevels contains the set of valid log levels

Functions

func CheckContext

func CheckContext(ctx context.Context) error

CheckContext returns an error if the context is cancelled This is useful for long-running operations that should respect cancellation

func FormatDockerID

func FormatDockerID(id string) string

FormatDockerID returns a shortened version of a Docker ID for logging This can be used for container IDs, network IDs, or any Docker resource ID

func GetDockerEnvVar

func GetDockerEnvVar(env []string, key string) string

GetDockerEnvVar extracts an environment variable value from a Docker container's env slice This is commonly used when inspecting containers to get specific environment variables

func HasManageableContainersInNetwork

func HasManageableContainersInNetwork(ctx context.Context, dockerClient *client.Client, networkID, excludeContainerName string) (bool, error)

HasManageableContainersInNetwork checks if a network has any manageable containers, optionally excluding a specific container

func Retry

func Retry(ctx context.Context, config RetryConfig, fn RetryableFunc) error

Retry executes a function with retry logic and exponential backoff It respects context cancellation and returns the last error encountered

func RetryContainerInspect

func RetryContainerInspect(ctx context.Context, dockerClient *client.Client, containerID string) (types.ContainerJSON, error)

RetryContainerInspect wraps ContainerInspect with retry logic

func RetryContainerList

func RetryContainerList(ctx context.Context, dockerClient *client.Client, options container.ListOptions) ([]types.Container, error)

RetryContainerList wraps ContainerList with retry logic

func RetryNetworkConnect

func RetryNetworkConnect(ctx context.Context, dockerClient *client.Client, networkID, containerName string, config *network.EndpointSettings) error

RetryNetworkConnect wraps NetworkConnect with retry logic

func RetryNetworkInspect

func RetryNetworkInspect(ctx context.Context, dockerClient *client.Client, networkID string, options network.InspectOptions) (network.Inspect, error)

RetryNetworkInspect wraps NetworkInspect with retry logic

func ShouldManageContainer

func ShouldManageContainer(env []string, labels map[string]string) bool

ShouldManageContainer checks if a container should be managed based on dinghy env vars or traefik labels Returns true if the container has VIRTUAL_HOST environment variable or traefik labels

func SliceToSet

func SliceToSet(slice []string) map[string]struct{}

SliceToSet converts a slice of strings to a map[string]struct{} for O(1) lookups This is useful for creating sets from slices where you only need to check existence

func ValidateLogLevel

func ValidateLogLevel(level string) error

ValidateLogLevel checks if the provided log level is valid

Types

type RetryConfig

type RetryConfig struct {
	// MaxAttempts is the maximum number of attempts (including the first one)
	MaxAttempts int
	// InitialDelay is the delay before the first retry
	InitialDelay time.Duration
	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration
	// BackoffMultiplier is the factor by which the delay increases after each retry
	BackoffMultiplier float64
}

RetryConfig configures retry behavior for operations

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns a sensible default retry configuration for Docker operations

type RetryableFunc

type RetryableFunc func(ctx context.Context) error

RetryableFunc is a function that can be retried. It should return an error if the operation should be retried, or nil if successful. The context can be used to cancel the operation.

Jump to

Keyboard shortcuts

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