config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides Docker container label parsing for roji configuration.

It extracts routing configuration from Docker labels such as:

  • roji.host: Custom hostname
  • roji.port: Target port
  • roji.path: Path prefix for path-based routing

Index

Constants

View Source
const (
	// Label prefix for all roji-related labels
	LabelPrefix = "roji."

	// Supported labels
	LabelHost = LabelPrefix + "host" // Custom hostname (default: {service}.{domain})
	LabelPort = LabelPrefix + "port" // Target port when multiple ports exposed
	LabelPath = LabelPrefix + "path" // Path prefix for routing (optional)

	// Mock labels prefix
	LabelMockPrefix       = LabelPrefix + "mock."       // roji.mock.GET./path = response body
	LabelMockStatusPrefix = LabelMockPrefix + "status." // roji.mock.status.GET./path = status code
)
View Source
const (
	// AppName is the application name used for directory paths
	AppName = "roji"
)

Variables

This section is empty.

Functions

func CertsDir added in v0.8.0

func CertsDir() string

CertsDir returns the certificates directory Defaults to DataDir()/certs

func ConfigDir added in v0.8.0

func ConfigDir() string

ConfigDir returns the configuration directory following XDG spec Linux/macOS: ~/.config/roji Windows: %APPDATA%\roji

func ConfigFilePath added in v0.8.0

func ConfigFilePath() string

ConfigFilePath returns the path to the configuration file

func DataDir added in v0.8.0

func DataDir() string

DataDir returns the data directory following XDG spec Linux/macOS: ~/.local/share/roji Windows: %LOCALAPPDATA%\roji

func DefaultHostname

func DefaultHostname(serviceName, baseDomain string) string

DefaultHostname generates a default hostname from service name and base domain e.g., ("myapp", "kan.localhost") -> "myapp.kan.localhost"

func EnsureDir added in v0.8.0

func EnsureDir(path string) error

EnsureDir creates a directory if it doesn't exist

func Exists added in v0.8.0

func Exists(path string) bool

Exists checks if a file or directory exists

Types

type MockRoute added in v0.6.0

type MockRoute struct {
	Method     string // HTTP method (GET, POST, etc.)
	Path       string // URL path (e.g., "/api/users")
	Body       string // Response body
	StatusCode int    // HTTP status code (default: 200)
}

MockRoute defines a mock response for a specific method and path

type Paths added in v0.8.0

type Paths struct {
	ConfigDir string // Directory for configuration files
	DataDir   string // Directory for data files (projects.json, etc.)
	CertsDir  string // Directory for certificates
}

Paths holds the resolved paths for configuration and data directories

func DefaultPaths added in v0.8.0

func DefaultPaths() *Paths

DefaultPaths returns the default paths following XDG Base Directory specification

type RouteConfig

type RouteConfig struct {
	Host       string       // e.g., "myapp.localhost"
	Port       int          // Target port
	PathPrefix string       // e.g., "/api" (optional)
	MockRoutes []*MockRoute // Mock responses for this container
}

RouteConfig holds the configuration for a single route

func ParseLabels

func ParseLabels(labels map[string]string) *RouteConfig

ParseLabels extracts roji configuration from container labels

type Settings added in v0.8.0

type Settings struct {
	Network   string `yaml:"network"`    // Docker network name(s) (comma-separated)
	Domain    string `yaml:"domain"`     // Base domain (e.g., dev.localhost)
	HTTPPort  int    `yaml:"http_port"`  // HTTP port (for redirect)
	HTTPSPort int    `yaml:"https_port"` // HTTPS port
	CertsDir  string `yaml:"certs_dir"`  // Directory for TLS certificates
	DataDir   string `yaml:"data_dir"`   // Directory for persistent data
	Dashboard string `yaml:"dashboard"`  // Dashboard hostname
	LogLevel  string `yaml:"log_level"`  // Log level (debug, info, warn, error)
	AutoCert  bool   `yaml:"auto_cert"`  // Auto-generate certificates
}

Settings holds all configuration settings for roji

func Defaults added in v0.8.0

func Defaults() *Settings

Defaults returns settings with default values

func Load added in v0.8.0

func Load(configPath string, cliOverrides map[string]any) (*Settings, error)

Load loads configuration with the following priority (highest to lowest): 1. CLI overrides (passed in cliOverrides) 2. Environment variables (ROJI_*) 3. Config file 4. Defaults

func (*Settings) Networks added in v0.8.0

func (s *Settings) Networks() []string

Networks returns the network names as a slice

func (*Settings) SaveToFile added in v0.8.0

func (s *Settings) SaveToFile(path string) error

SaveToFile saves settings to a YAML file

func (*Settings) ToYAML added in v0.8.0

func (s *Settings) ToYAML() (string, error)

ToYAML returns the settings as YAML string

Jump to

Keyboard shortcuts

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