config

package
v0.0.0-...-3a05b22 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YmlExtension            = "yml"
	YamlExtension           = "yaml"
	DefaultSearchConfigName = "config"
	DefaultSearchConfigType = YamlExtension // yaml

	SearchPathEnvKey    = "IOC_GOLANG_CONFIG_SEARCH_PATH"
	TypeEnvKey          = "IOC_GOLANG_CONFIG_TYPE"
	NameEnvKey          = "IOC_GOLANG_CONFIG_NAME"
	ActiveProfileEnvKey = "IOC_GOLANG_CONFIG_ACTIVE_PROFILE"

	YamlConfigSeparator = "."
	EnvValueSeparator   = ","
)
View Source
const (
	EnvPrefixKey = "${"
	EnvSuffixKey = "}"
	And          = "&"
)
View Source
const (
	PathSeparator = string(os.PathSeparator)
)

Variables

View Source
var (
	DefaultSearchPath = []string{".", "./config", "./configs"}
)

Functions

func ExpandConfigEnvValue

func ExpandConfigEnvValue(targetValue interface{}) (interface{}, bool)

func ExpandConfigNestedValue

func ExpandConfigNestedValue(targetValue interface{}) (interface{}, bool)

func ExpandConfigValueIfNecessary

func ExpandConfigValueIfNecessary(targetValue interface{}) interface{}

func GetActiveProfiles

func GetActiveProfiles() []string

func Load

func Load(opts ...Option) error

func LoadConfigByPrefix

func LoadConfigByPrefix(prefix string, configStructPtr interface{}) error

LoadConfigByPrefix prefix is like 'a.b.c' or 'a.b.<github.com/xxx/xx/xxx.Impl>.c', configStructPtr is interface ptr

func LoggerConfig

func LoggerConfig() common.Config

func SetConfig

func SetConfig(yamlBytes []byte) error

Types

type AnyMap

type AnyMap = map[string]interface{} // alias

func MergeMap

func MergeMap(dst, src AnyMap, maxDepths ...uint8) AnyMap

MergeMap

@dangerous trigger PANIC

@return dst

type Config

type Config AnyMap

type Option

type Option func(opts *Options)

func AddProperty

func AddProperty(key string, value interface{}) Option

func WithAbsPath

func WithAbsPath(absPath ...string) Option

func WithConfigName

func WithConfigName(configName string) Option

func WithConfigType

func WithConfigType(configType string) Option

func WithMergeDepth

func WithMergeDepth(mergeDepth uint8) Option

func WithProfilesActive

func WithProfilesActive(profilesActive ...string) Option

func WithSearchPath

func WithSearchPath(searchPath ...string) Option

type Options

type Options struct {
	AbsPath []string // abs path -> high level priority

	// default: config
	ConfigName string
	// default: yaml
	ConfigType string
	// Search path of config files
	//
	// default: ., ./config, ./configs;
	//
	// priority: ./ > ./config > ./configs
	SearchPath []string
	// Profiles active
	//
	// default: []string
	//
	// e.g.:
	//
	// []string{"dev","share"}
	//
	// search target: config.yml/config_dev.yml/config_share.yml
	ProfilesActive []string
	// Depth of merging under multiple config files
	MergeDepth uint8
	// Properties set by API
	Properties AnyMap
}

Jump to

Keyboard shortcuts

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