config

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: AGPL-3.0 Imports: 12 Imported by: 98

Documentation

Overview

Package config uses the exact same precedence order as Viper, where each item takes precedence over the item below it:

  • explicit call to Set (case insensitive)
  • flag (case insensitive)
  • env (case sensitive - see notes below)
  • config (case insensitive)
  • key/value store (case insensitive)
  • default (case insensitive)

Environment variable resolution is performed based on the following rules:

  • If the key contains only uppercase characters, numbers and underscores, the environment variable is looked up in its entirety, e.g. SOME_VARIABLE -> SOME_VARIABLE
  • In all other cases, the environment variable is transformed before being looked up as following: 1. camelCase is converted to snake_case, e.g. someVariable -> some_variable 2. dots (.) are replaced with underscores (_), e.g. some.variable -> some_variable 3. the resulting string is uppercased and prefixed with ${PREFIX}_ (default RSERVER_), e.g. some_variable -> RSERVER_SOME_VARIABLE

Index

Constants

View Source
const (
	EmbeddedMode       = "embedded"
	MasterMode         = "master"
	MasterSlaveMode    = "master_and_slave"
	SlaveMode          = "slave"
	OffMode            = "off"
	EmbeddedMasterMode = "embedded_master"
)

Rudder server supported config constants

View Source
const DefaultEnvPrefix = "RSERVER"

Variables

This section is empty.

Functions

func ConfigKeyToEnv

func ConfigKeyToEnv(envPrefix, s string) string

ConfigKeyToEnv gets the env variable name from a given config key

func GetBool

func GetBool(key string, defaultValue bool) (value bool)

GetBool gets bool value from config

func GetDuration

func GetDuration(key string, defaultValueInTimescaleUnits int64, timeScale time.Duration) (value time.Duration)

GetDuration gets duration value from config

func GetFloat64

func GetFloat64(key string, defaultValue float64) (value float64)

GetFloat64 gets float64 value from config

func GetInstanceID

func GetInstanceID() string

func GetInt

func GetInt(key string, defaultValue int) (value int)

GetInt gets int value from config

func GetInt64

func GetInt64(key string, defaultValue int64) (value int64)

GetInt64 gets int64 value from config

func GetKubeNamespace

func GetKubeNamespace() string

GetKubeNamespace returns value stored in KUBE_NAMESPACE env var

func GetNamespaceIdentifier

func GetNamespaceIdentifier() string

GetNamespaceIdentifier returns value stored in KUBE_NAMESPACE env var or "none" if empty

func GetReleaseName

func GetReleaseName() string

func GetString

func GetString(key, defaultValue string) (value string)

GetString gets string value from config

func GetStringMap

func GetStringMap(key string, defaultValue map[string]interface{}) (value map[string]interface{})

GetStringMap gets string map value from config

func GetStringSlice

func GetStringSlice(key string, defaultValue []string) (value []string)

GetStringSlice gets string slice value from config

func GetWorkspaceToken

func GetWorkspaceToken() string

GetWorkspaceToken returns the workspace token provided in the environment variables Env variable CONFIG_BACKEND_TOKEN is deprecating soon WORKSPACE_TOKEN is newly introduced. This will override CONFIG_BACKEND_TOKEN

func IsSet

func IsSet(key string) bool

IsSet checks if config is set for a key

func MustGetInt

func MustGetInt(key string) (value int)

MustGetInt gets int value from config or panics if the config doesn't exist

func MustGetString

func MustGetString(key string) (value string)

MustGetString gets string value from config or panics if the config doesn't exist

func RegisterBoolConfigVariable

func RegisterBoolConfigVariable(defaultValue bool, ptr *bool, isHotReloadable bool, keys ...string)

RegisterBoolConfigVariable registers bool config variable

func RegisterDurationConfigVariable

func RegisterDurationConfigVariable(defaultValueInTimescaleUnits int64, ptr *time.Duration, isHotReloadable bool, timeScale time.Duration, keys ...string)

RegisterDurationConfigVariable registers duration config variable

func RegisterFloat64ConfigVariable

func RegisterFloat64ConfigVariable(defaultValue float64, ptr *float64, isHotReloadable bool, keys ...string)

RegisterFloat64ConfigVariable registers float64 config variable

func RegisterInt64ConfigVariable

func RegisterInt64ConfigVariable(defaultValue int64, ptr *int64, isHotReloadable bool, valueScale int64, keys ...string)

RegisterInt64ConfigVariable registers int64 config variable

func RegisterIntConfigVariable

func RegisterIntConfigVariable(defaultValue int, ptr *int, isHotReloadable bool, valueScale int, keys ...string)

RegisterIntConfigVariable registers int config variable

func RegisterStringConfigVariable

func RegisterStringConfigVariable(defaultValue string, ptr *string, isHotReloadable bool, keys ...string)

RegisterStringConfigVariable registers string config variable

func RegisterStringMapConfigVariable

func RegisterStringMapConfigVariable(defaultValue map[string]interface{}, ptr *map[string]interface{}, isHotReloadable bool, keys ...string)

RegisterStringMapConfigVariable registers string map config variable

func RegisterStringSliceConfigVariable

func RegisterStringSliceConfigVariable(defaultValue []string, ptr *[]string, isHotReloadable bool, keys ...string)

RegisterStringSliceConfigVariable registers string slice config variable

func Reset

func Reset()

Reset resets the default, singleton config instance. Shall only be used by tests, until we move to a proper DI framework

func Set

func Set(key string, value interface{})

Set override existing config

Types

type Config

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

Config is the entry point for accessing configuration

var Default *Config

default, singleton config instance

func New

func New(opts ...Opt) *Config

New creates a new config instance

func (*Config) GetBool

func (c *Config) GetBool(key string, defaultValue bool) (value bool)

GetBool gets bool value from config

func (*Config) GetDuration

func (c *Config) GetDuration(key string, defaultValueInTimescaleUnits int64, timeScale time.Duration) (value time.Duration)

GetDuration gets duration value from config

func (*Config) GetFloat64

func (c *Config) GetFloat64(key string, defaultValue float64) (value float64)

GetFloat64 gets float64 value from config

func (*Config) GetInt

func (c *Config) GetInt(key string, defaultValue int) (value int)

GetInt gets int value from config

func (*Config) GetInt64

func (c *Config) GetInt64(key string, defaultValue int64) (value int64)

GetInt64 gets int64 value from config

func (*Config) GetString

func (c *Config) GetString(key, defaultValue string) (value string)

GetString gets string value from config

func (*Config) GetStringMap

func (c *Config) GetStringMap(key string, defaultValue map[string]interface{}) (value map[string]interface{})

GetStringMap gets string map value from config

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(key string, defaultValue []string) (value []string)

GetStringSlice gets string slice value from config

func (*Config) IsSet

func (c *Config) IsSet(key string) bool

IsSet checks if config is set for a key

func (*Config) MustGetInt

func (c *Config) MustGetInt(key string) (value int)

MustGetInt gets int value from config or panics if the config doesn't exist

func (*Config) MustGetString

func (c *Config) MustGetString(key string) (value string)

MustGetString gets string value from config or panics if the config doesn't exist

func (*Config) RegisterBoolConfigVariable

func (c *Config) RegisterBoolConfigVariable(defaultValue bool, ptr *bool, isHotReloadable bool, keys ...string)

RegisterBoolConfigVariable registers bool config variable

func (*Config) RegisterDurationConfigVariable

func (c *Config) RegisterDurationConfigVariable(defaultValueInTimescaleUnits int64, ptr *time.Duration, isHotReloadable bool, timeScale time.Duration, keys ...string)

RegisterDurationConfigVariable registers duration config variable

func (*Config) RegisterFloat64ConfigVariable

func (c *Config) RegisterFloat64ConfigVariable(defaultValue float64, ptr *float64, isHotReloadable bool, keys ...string)

RegisterFloat64ConfigVariable registers float64 config variable

func (*Config) RegisterInt64ConfigVariable

func (c *Config) RegisterInt64ConfigVariable(defaultValue int64, ptr *int64, isHotReloadable bool, valueScale int64, keys ...string)

RegisterInt64ConfigVariable registers int64 config variable

func (*Config) RegisterIntConfigVariable

func (c *Config) RegisterIntConfigVariable(defaultValue int, ptr *int, isHotReloadable bool, valueScale int, keys ...string)

RegisterIntConfigVariable registers int config variable

func (*Config) RegisterStringConfigVariable

func (c *Config) RegisterStringConfigVariable(defaultValue string, ptr *string, isHotReloadable bool, keys ...string)

RegisterStringConfigVariable registers string config variable

func (*Config) RegisterStringMapConfigVariable

func (c *Config) RegisterStringMapConfigVariable(defaultValue map[string]interface{}, ptr *map[string]interface{}, isHotReloadable bool, keys ...string)

RegisterStringMapConfigVariable registers string map config variable

func (*Config) RegisterStringSliceConfigVariable

func (c *Config) RegisterStringSliceConfigVariable(defaultValue []string, ptr *[]string, isHotReloadable bool, keys ...string)

RegisterStringSliceConfigVariable registers string slice config variable

func (*Config) Set

func (c *Config) Set(key string, value interface{})

Set override existing config

type Opt

type Opt func(*Config)

func WithEnvPrefix

func WithEnvPrefix(prefix string) Opt

WithEnvPrefix sets the environment variable prefix (default: RSERVER)

Jump to

Keyboard shortcuts

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