config

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// LoggingFormat defines the logging format used for log messages. Allowed values are "json" and "text".
	LoggingFormat = NewKey("logging.format",
		WithDefaultValue("text"),
		WithAllowedStrings([]string{"json", "text"}))

	// LoggingColors specifies whether log messages are displayed with color-coded
	// output. This only applies when LoggingFormat is set to "text".
	LoggingColors = NewKey("logging.colors",
		WithDefaultValue(true),
		WithValidBool())

	// LoggingTimeFormat specifies the time format used for log messages. The default is 15:04:05.
	LoggingTimeFormat = NewKey("logging.timeFormat",
		WithDefaultValue("15:04:05"))

	// LoggingOutput specifies the destination where log messages created by the
	// application are sent. It defaults to stdout.
	LoggingOutput = NewKey("logging.output",
		WithDefaultValue("stdout"))

	// LoggingLevel specifies the minimum severity a log message must meet to be
	// recorded.
	LoggingLevel = NewKey("logging.level",
		WithDefaultValue("INFO"),
		WithAllowedStrings([]string{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "PANIC", "DISABLED"}))
)
View Source
var (
	// SyncS3MaxConcurrentUploads is the maximum number of concurrent uploads to S3.
	SyncS3MaxConcurrentUploads = NewKey("sync.s3.maxConcurrentUploads",
		WithDefaultValue(10),
		WithValidInt())

	// SyncS3ObjectCacheEnabled enables S3 object-seem cache.
	SyncS3ObjectCacheEnabled = NewKey("sync.s3.objectCache.enabled",
		WithDefaultValue(true),
		WithValidBool())

	// SyncS3ObjectCacheExpirationTime is the expiration time for S3 object cache.
	SyncS3ObjectCacheExpirationTime = NewKey("sync.s3.objectCache.expirationTime",
		WithDefaultValue(10*time.Minute),
		WithValidDuration())

	// SyncS3ObjectCacheCapacity is the maximum number of entries the S3 object cache can hold.
	SyncS3ObjectCacheCapacity = NewKey("sync.s3.objectCache.capacity",
		WithDefaultValue(1000),
		WithValidInt())
)
View Source
var (

	// SyncMaxErrors specifies the maximum number of errors that can occur before the application exits.
	SyncMaxErrors = NewKey("sync.maxErrors",
		WithDefaultValue(5),
		WithValidInt())

	// SyncInterval specifies the interval at which images are synchronized.
	SyncInterval = NewKey("sync.interval",
		WithDefaultValue("30m"),
		WithValidDuration())

	// SyncRegistries specifies the repositories to use for pulling and pushing images.
	SyncRegistries = NewKey("sync.registries",
		WithDefaultValue([]map[string]interface{}{
			{
				"name": "Docker Hub",
				"url":  "docker.io",
				"auth": map[string]interface{}{
					"username": "",
					"password": "",
					"token":    "",
					"helper":   "",
				},
			},
		}),
		WithValidRepositories())

	// SyncImages specifies the images to synchronize.
	SyncImages = NewKey("sync.images",
		WithDefaultValue([]map[string]interface{}{
			{
				"source": "docker.io/library/ubuntu",
				"targets": []string{
					"docker.io/library/ubuntu",
				},
				"tags": []string{},
				"mutableTags": []string{
					"latest",
				},
				"ignoredTags": []string{},
			},
		}),
		WithValidImages())
)
View Source
var (

	// TelemetryEnabled indicates whether telemetry is enabled.
	TelemetryEnabled = NewKey("telemetry.enabled",
		WithDefaultValue(false),
		WithValidBool())

	// TelemetryMetricsExporter specifies the metrics exporter used for telemetry.
	TelemetryMetricsExporter = NewKey("telemetry.metrics.exporter",
		WithDefaultValue("prometheus"),
		WithAllowedStrings([]string{"prometheus", "stdout"}))

	// TelemetryMetricsPrometheusAddress specifies the network address for the Prometheus.
	TelemetryMetricsPrometheusAddress = NewKey("telemetry.metrics.prometheus.address",
		WithDefaultValue("127.0.0.1:9090"),
		WithValidNetHostPort())

	// TelemetryMetricsPrometheusPath specifies the path for the Prometheus metrics endpoint.
	TelemetryMetricsPrometheusPath = NewKey("telemetry.metrics.prometheus.path",
		WithDefaultValue("/metrics"),
		WithValidURI())

	// TelemetryMetricsStdoutInterval specifies the sampling interval for sending metrics to stdout.
	TelemetryMetricsStdoutInterval = NewKey("telemetry.metrics.stdout.interval",
		WithDefaultValue("5s"),
		WithValidDuration())
)
View Source
var (
	ECRRegion = NewKey("ecr.region",
		WithDefaultValue("us-east-1"),
		WithValidString())
)
View Source
var Version = "dev"

Version specifies the current version of the application. It defaults to "dev" to indicate development mode but can be set to reflect the release version during the build process.

Functions

func InitConfig

func InitConfig(cfgFile string) error

InitConfig initializes the application's configuration system. It loads settings from a specified file, environment variables, or search paths, and listens for changes to dynamically update the configuration.

Types

type Key

type Key struct {
	Name            string
	Default         interface{}
	Value           interface{}
	ValidationFuncs []func(interface{}) error
	// contains filtered or unexported fields
}

func NewKey

func NewKey(name string, opts ...KeyOption) *Key

NewKey creates a new configuration key with the specified name and additional options.

func (*Key) Bool

func (k *Key) Bool() bool

func (*Key) Duration

func (k *Key) Duration() time.Duration

func (*Key) Float64

func (k *Key) Float64() float64

func (*Key) Images

func (k *Key) Images() []*structs.Image

func (*Key) Int

func (k *Key) Int() int

func (*Key) Int64

func (k *Key) Int64() int64

func (*Key) Repositories

func (k *Key) Repositories() []*structs.Repository

func (*Key) String

func (k *Key) String() string

Mimic the behavior of viper.Get???() calls.

func (*Key) StringSlice

func (k *Key) StringSlice() []string

func (*Key) UInt64

func (k *Key) UInt64() uint64

func (*Key) Update

func (k *Key) Update() *ReloadedKey

type KeyOption

type KeyOption func(*Key)

func WithAllowedInts

func WithAllowedInts(values []int) KeyOption

WithAllowedInts sets the allowed values for the configuration key.

func WithAllowedStrings

func WithAllowedStrings(values []string) KeyOption

WithAllowedStrings sets the allowed values for the configuration key.

func WithDefaultValue

func WithDefaultValue(defaultValue interface{}) KeyOption

WithDefaultValue sets the default value for the configuration key.

func WithValidBool

func WithValidBool() KeyOption

WithValidBool checks if the value is a boolean.

func WithValidDuration

func WithValidDuration() KeyOption

WithValidDuration checks if the value is a duration.

func WithValidExistingPathOrEmpty

func WithValidExistingPathOrEmpty() KeyOption

WithValidExistingPathOrEmpty checks if the value is an existing path or if it is empty.

func WithValidFloat64

func WithValidFloat64() KeyOption

WithValidFloat64 checks if the value is a float64.

func WithValidImages

func WithValidImages() KeyOption

WithValidImages checks if the value is a valid image.

func WithValidInt

func WithValidInt() KeyOption

WithValidInt checks if the value is an integer.

func WithValidMap

func WithValidMap() KeyOption

WithValidMap checks if the value is a map.

func WithValidNetHostPort

func WithValidNetHostPort() KeyOption

WithValidNetHostPort checks if the value is a valid host:port string.

func WithValidPositiveInt

func WithValidPositiveInt() KeyOption

WithValidPositiveInt checks if the value is a positive integer.

func WithValidRepositories

func WithValidRepositories() KeyOption

WithValidRepositories checks if the value is a valid repository.

func WithValidString

func WithValidString() KeyOption

WithValidString checks if the value is a string.

func WithValidStringSlice

func WithValidStringSlice() KeyOption

WithValidStringSlice checks if the value is a string slice.

func WithValidURI

func WithValidURI() KeyOption

WithValidURI checks if the value is a valid URI.

func WithValidURL

func WithValidURL() KeyOption

WithValidURL checks if the value is a valid URL.

func WithValidationFunc

func WithValidationFunc(f func(interface{}) error) KeyOption

WithValidationFunc adds a validation function for the configuration key.

type ReloadedKey

type ReloadedKey struct {
	Key      string
	Error    error
	OldValue interface{}
	NewValue interface{}
}

func Reload

func Reload() []*ReloadedKey

Jump to

Keyboard shortcuts

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