config

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Lang is the language to use for translation
	Lang = ffc("lang")
	// LogForceColor forces color to be enabled, even if we do not detect a TTY
	LogForceColor = ffc("log.forceColor")
	// LogLevel is the logging level
	LogLevel = ffc("log.level")
	// LogNoColor forces color to be disabled, even if we detect a TTY
	LogNoColor = ffc("log.noColor")
	// LogTimeFormat is a string format for timestamps
	LogTimeFormat = ffc("log.timeFormat")
	// LogUTC sets log timestamps to the UTC timezone
	LogUTC = ffc("log.utc")
	// LogFilename sets logging to file
	LogFilename = ffc("log.filename")
	// LogFilesize sets the size to roll logs at
	LogFilesize = ffc("log.filesize")
	// LogMaxBackups sets the maximum number of old files to keep
	LogMaxBackups = ffc("log.maxBackups")
	// LogMaxAge sets the maximum age at which to roll
	LogMaxAge = ffc("log.maxAge")
	// LogCompress sets whether to compress backups
	LogCompress = ffc("log.compress")
	// LogIncludeCodeInfo enables the report caller for including the calling file and line number
	LogIncludeCodeInfo = ffc("log.includeCodeInfo")
	// LogJSONEnabled enables JSON formatted logs rather than text
	LogJSONEnabled = ffc("log.json.enabled")
	// LogJSONTimestampField configures the JSON key containing the timestamp of the log
	LogJSONTimestampField = ffc("log.json.fields.timestamp")
	// LogJSONLevelField configures the JSON key containing the log level
	LogJSONLevelField = ffc("log.json.fields.level")
	// LogJSONMessageField configures the JSON key containing the log message
	LogJSONMessageField = ffc("log.json.fields.message")
	// LogJSONFuncField configures the JSON key containing the calling function
	LogJSONFuncField = ffc("log.json.fields.func")
	// LogJSONFileField configures the JSON key containing the calling file
	LogJSONFileField = ffc("log.json.fields.file")
)

The following keys can be access from the root configuration. Plugins are responsible for defining their own keys using the Config interface

Functions

func GenerateConfigMarkdown

func GenerateConfigMarkdown(ctx context.Context, header string, keys []string) ([]byte, error)

func Get

func Get(key RootKey) interface{}

Get gets a configuration in raw form

func GetBool

func GetBool(key RootKey) bool

GetBool gets a configuration bool

func GetByteSize

func GetByteSize(key RootKey) int64

GetByteSize get a size in bytes

func GetConfig

func GetConfig() fftypes.JSONObject

func GetDuration

func GetDuration(key RootKey) time.Duration

GetDuration gets a configuration time duration with consistent semantics

func GetFloat64

func GetFloat64(key RootKey) float64

GetFloat64 gets a configuration uint

func GetInt

func GetInt(key RootKey) int

GetInt gets a configuration uint

func GetInt64

func GetInt64(key RootKey) int64

GetInt64 gets a configuration int64

func GetKnownKeys

func GetKnownKeys() []string

GetKnownKeys gets the known keys

func GetObject

func GetObject(key RootKey) fftypes.JSONObject

GetObject gets a configuration map

func GetObjectArray

func GetObjectArray(key RootKey) fftypes.JSONObjectArray

GetObjectArray gets an array of configuration maps

func GetString

func GetString(key RootKey) string

GetString gets a configuration string

func GetStringSlice

func GetStringSlice(key RootKey) []string

GetStringSlice gets a configuration string array

func GetUint

func GetUint(key RootKey) uint

GetUint gets a configuration uint

func GetUint64 added in v1.2.8

func GetUint64(key RootKey) uint64

GetUint64 gets a configuration uint64

func IsSet added in v1.1.1

func IsSet(key RootKey) bool

func MergeConfig

func MergeConfig(configRecords []*fftypes.ConfigRecord) error

func ReadConfig

func ReadConfig(cfgSuffix, cfgFile string) error

ReadConfig initializes the config

func RootConfigReset

func RootConfigReset(setServiceDefaults ...func())

func Set

func Set(key RootKey, value interface{})

Set allows runtime setting of config (used in unit tests)

func SetupLogging

func SetupLogging(ctx context.Context)

SetupLogging initializes logging

func ShowConfigCommand added in v1.2.8

func ShowConfigCommand(initConf func() error) *cobra.Command

func WatchConfig added in v1.2.0

func WatchConfig(ctx context.Context, onChange, onClose func()) error

Listens for changes to the configuration file configured in Viper.

Types

type ArraySection added in v0.1.4

type ArraySection interface {
	KeySet
	ArraySize() int
	ArrayEntry(i int) Section
	SubSection(name string) Section
	SubArray(name string) ArraySection
	SetDefault(key string, defValue interface{})
}

ArraySection represents an array of options at a particular layer in the config. This allows specifying the schema of keys that exist for every entry, and the defaults, as well as querying how many entries exist and iterating through them.

func RootArray added in v0.1.4

func RootArray(prefix string) ArraySection

RootArray creates a new configuration array starting from the config root

type KeySet

type KeySet interface {
	AddKnownKey(key string, defValue ...interface{})
}

type RootKey

type RootKey string

RootKey key are the known configuration keys

func AddRootKey

func AddRootKey(k string) RootKey

AddRootKey adds a root key, used to define the keys that are used within the core

type Section added in v0.1.4

type Section interface {
	KeySet
	SetDefault(key string, defValue interface{})
	SubSection(name string) Section
	SubArray(name string) ArraySection
	Set(key string, value interface{})
	IsSet(key string) bool
	Resolve(key string) string

	GetString(key string) string
	GetBool(key string) bool
	GetInt(key string) int
	GetInt64(key string) int64
	GetFloat64(key string) float64
	GetByteSize(key string) int64
	GetUint(key string) uint
	GetUint64(key string) uint64
	GetDuration(key string) time.Duration
	GetStringSlice(key string) []string
	GetObject(key string) fftypes.JSONObject
	GetObjectArray(key string) fftypes.JSONObjectArray
	Get(key string) interface{}
}

Section represents a section of the global configuration, at a nested point in the config hierarchy. Note that all keys are added to a GLOBAL map, so this cannot be used for per-instance customization.

func RootSection added in v0.1.4

func RootSection(prefix string) Section

RootSection creates a new configuration section starting from the config root

Jump to

Keyboard shortcuts

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