cfg

package
v0.26.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultEnvKeyReplacer = strings.NewReplacer(".", "_", "-", "_")
)

Functions

func AddPostProcessor

func AddPostProcessor(priority int, name string, processor PostProcessor)

func ApplyPostProcessors

func ApplyPostProcessors(config GosoConf) (map[string]int, error)

func DebugConfig

func DebugConfig(config Config, logger Logger) error

func Merge

func Merge(target interface{}, source interface{}) error

func NewMemoryEnvProvider

func NewMemoryEnvProvider(initialValues ...map[string]string) *memoryEnvProvider

func NewOsEnvProvider

func NewOsEnvProvider() *osEnvProvider

func PanicErrorHandler

func PanicErrorHandler(msg string, args ...interface{})

func Sanitize

func Sanitize(key string, value interface{}, sanitizers []Sanitizer) (interface{}, error)

func SkipExisting

func SkipExisting() func(mode *mapx.OpMode)

func StringToTimeHookFunc

func StringToTimeHookFunc(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)

func TimeSanitizer

func TimeSanitizer(in interface{}) (interface{}, error)

func WithDefaultErrorHandler

func WithDefaultErrorHandler(handler ErrorHandler)

Types

type AppId

type AppId struct {
	Project     string `cfg:"project" default:"{app_project}" json:"project"`
	Environment string `cfg:"environment" default:"{env}" json:"environment"`
	Family      string `cfg:"family" default:"{app_family}" json:"family"`
	Group       string `cfg:"group" default:"{app_group}" json:"group"`
	Application string `cfg:"application" default:"{app_name}" json:"application"`
}

func GetAppIdFromConfig

func GetAppIdFromConfig(config Config) AppId

func (*AppId) PadFromConfig

func (i *AppId) PadFromConfig(config Config)

func (*AppId) String

func (i *AppId) String() string

type Config

type Config interface {
	AllKeys() []string
	AllSettings() map[string]interface{}
	Get(key string, optionalDefault ...interface{}) interface{}
	GetBool(key string, optionalDefault ...bool) bool
	GetDuration(key string, optionalDefault ...time.Duration) time.Duration
	GetInt(key string, optionalDefault ...int) int
	GetIntSlice(key string, optionalDefault ...[]int) []int
	GetFloat64(key string, optionalDefault ...float64) float64
	GetMsiSlice(key string, optionalDefault ...[]map[string]interface{}) []map[string]interface{}
	GetString(key string, optionalDefault ...string) string
	GetStringMap(key string, optionalDefault ...map[string]interface{}) map[string]interface{}
	GetStringMapString(key string, optionalDefault ...map[string]string) map[string]string
	GetStringSlice(key string, optionalDefault ...[]string) []string
	GetTime(key string, optionalDefault ...time.Time) time.Time
	IsSet(string) bool
	HasPrefix(prefix string) bool
	UnmarshalDefaults(val interface{}, additionalDefaults ...UnmarshalDefaults)
	UnmarshalKey(key string, val interface{}, additionalDefaults ...UnmarshalDefaults)
}

type EnvProvider

type EnvProvider interface {
	LookupEnv(key string) (string, bool)
	PrefixExists(prefix string) bool
	SetEnv(key string, value string) error
}

type ErrorHandler

type ErrorHandler func(msg string, args ...interface{})

func LoggerErrorHandler

func LoggerErrorHandler(logger Logger) ErrorHandler

func SentryErrorHandler

func SentryErrorHandler(sentry Sentry) ErrorHandler

type GosoConf

type GosoConf interface {
	Config
	Option(options ...Option) error
}

func New

func New(msis ...map[string]interface{}) GosoConf

func NewWithInterfaces

func NewWithInterfaces(envProvider EnvProvider, msis ...map[string]interface{}) GosoConf

type Logger

type Logger interface {
	Info(format string, args ...interface{})
	Error(format string, args ...interface{})
}

type LookupEnv

type LookupEnv func(key string) (string, bool)

type MergeOption

type MergeOption func() func(mode *mapx.OpMode)

type Option

type Option func(cfg *config) error

func WithConfigFile

func WithConfigFile(filePath string, fileType string) Option

func WithConfigFileFlag

func WithConfigFileFlag(flagName string) Option

func WithConfigMap

func WithConfigMap(settings map[string]interface{}, mergeOptions ...MergeOption) Option

func WithConfigSetting

func WithConfigSetting(key string, settings interface{}, mergeOptions ...MergeOption) Option

func WithEnvKeyPrefix

func WithEnvKeyPrefix(prefix string) Option

func WithEnvKeyReplacer

func WithEnvKeyReplacer(replacer *strings.Replacer) Option

func WithErrorHandlers

func WithErrorHandlers(handlers ...ErrorHandler) Option

func WithSanitizers

func WithSanitizers(sanitizer ...Sanitizer) Option

type PostProcessor

type PostProcessor func(cfg GosoConf) (bool, error)

type Sanitizer

type Sanitizer func(in interface{}) (interface{}, error)

type Sentry

type Sentry interface {
	CaptureException(exception error, hint *sentry.EventHint, scope sentry.EventModifier) *sentry.EventID
}

type UnmarshalDefaults

type UnmarshalDefaults func(config Config, finalSettings *mapx.MapX)

func UnmarshalWithDefaultForKey

func UnmarshalWithDefaultForKey(targetKey string, setting interface{}) UnmarshalDefaults

func UnmarshalWithDefaultsFromKey

func UnmarshalWithDefaultsFromKey(sourceKey string, targetKey string) UnmarshalDefaults

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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