config

package
v0.0.0-...-ca3831e Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config provides a global config store that other packages can utilise for fetching/storing configuration. The config store supports both file and environment configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigEnvPrefix defines the environment variable prefix for reading server configuration from the environment.
	// This can be overridden to provide a customised default environment prefix for an app.
	ConfigEnvPrefix = "APP_"
	// ErrLoadConfig is the sentinel error returned when there was an issue loading the config.
	ErrLoadConfig = errors.New("error loading config")
	// ErrInvalidConfig is the sentinel error returned when the config was loaded but contains invalid values.
	ErrInvalidConfig = errors.New("invalid config")
)

Functions

func GetAppName

func GetAppName() string

func GetBaseURL

func GetBaseURL() string

func GetVersion

func GetVersion() string

func IsProduction

func IsProduction() bool

func Load

func Load[T any](envPrefix string, cfg T) error

Load will load a config via environment variables with the given prefix into an object of the given type.

Types

type ContainerRuntime

type ContainerRuntime string

ContainerRuntime identifies the detected container environment.

const (
	RuntimeNone     ContainerRuntime = "none"
	RuntimeDocker   ContainerRuntime = "docker"
	RuntimePodman   ContainerRuntime = "podman"
	RuntimeCloudRun ContainerRuntime = "cloudrun"
	RuntimeUnknown  ContainerRuntime = "unknown-container"
)

func DetectContainerRuntime

func DetectContainerRuntime() ContainerRuntime

DetectContainerRuntime tries to identify the container runtime we're executing under, checking the most specific/reliable signals first.

type Duration

type Duration struct {
	time.Duration
}

func NewDuration

func NewDuration(duration time.Duration) Duration

func (Duration) MarshalText

func (t Duration) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. Serializes Duration to a plain byte slice.

func (*Duration) UnmarshalText

func (t *Duration) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. Deserializes a plain byte slice into a Duration.

func (Duration) Validate

func (t Duration) Validate() error

type Environment

type Environment string

Environment is the app running environment.

const (
	// EnvDevelopment represents a development environment.
	EnvDevelopment Environment = "development"
	// EnvProduction represents a production environment.
	EnvProduction Environment = "production"
)

func GetEnvironment

func GetEnvironment() Environment

func (Environment) String

func (e Environment) String() string

Jump to

Keyboard shortcuts

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