Documentation
¶
Index ¶
- Variables
- func AddPostProcessor(priority int, name string, processor PostProcessor)
- func ApplyPostProcessors(config GosoConf) (map[string]int, error)
- func DebugConfig(ctx context.Context, config Config, logger Logger) error
- func Merge(target any, source any) error
- func NewMemoryEnvProvider(initialValues ...map[string]string) *memoryEnvProvider
- func NewOsEnvProvider() *osEnvProvider
- func Sanitize(key string, value any, sanitizers []Sanitizer) (any, error)
- func SkipExisting() func(mode *mapx.OpMode)
- func StringToTimeHookFunc(f reflect.Type, t reflect.Type, data any) (any, error)
- func TimeSanitizer(in any) (any, error)
- type Config
- type EnvProvider
- type GosoConf
- type Identity
- func (i Identity) Format(pattern string, delimiter string, args ...map[string]string) (string, error)
- func (i Identity) FormatNamespace(delimiter string, args ...map[string]string) (string, error)
- func (i *Identity) PadFromConfig(config Config) error
- func (i Identity) ToPlaceholders(delimiter string, args ...map[string]string) (map[string]string, error)
- type Logger
- type LookupEnv
- type MergeOption
- type Option
- func WithConfigBytes(bytes []byte, format string) Option
- func WithConfigFile(filePath string, fileType string) Option
- func WithConfigFileFlag(flagName string) Option
- func WithConfigMap(settings map[string]any, mergeOptions ...MergeOption) Option
- func WithConfigSetting(key string, settings any, mergeOptions ...MergeOption) Option
- func WithEnvKeyPrefix(prefix string) Option
- func WithEnvKeyReplacer(replacer *strings.Replacer) Option
- func WithSanitizers(sanitizer ...Sanitizer) Option
- type PostProcessor
- type ResourceIdentifier
- type Sanitizer
- type Tags
- type UnmarshalDefaults
Constants ¶
This section is empty.
Variables ¶
var (
DefaultEnvKeyReplacer = strings.NewReplacer(".", "_", "-", "_")
)
Functions ¶
func AddPostProcessor ¶
func AddPostProcessor(priority int, name string, processor PostProcessor)
func NewMemoryEnvProvider ¶
func NewOsEnvProvider ¶
func NewOsEnvProvider() *osEnvProvider
func SkipExisting ¶
func StringToTimeHookFunc ¶
func TimeSanitizer ¶
Types ¶
type Config ¶
type Config interface {
AllKeys() []string
AllSettings() map[string]any
Get(key string, optionalDefault ...any) (any, error)
GetBool(key string, optionalDefault ...bool) (bool, error)
GetDuration(key string, optionalDefault ...time.Duration) (time.Duration, error)
GetInt(key string, optionalDefault ...int) (int, error)
GetIntSlice(key string, optionalDefault ...[]int) ([]int, error)
GetFloat64(key string, optionalDefault ...float64) (float64, error)
GetMsiSlice(key string, optionalDefault ...[]map[string]any) ([]map[string]any, error)
GetString(key string, optionalDefault ...string) (string, error)
GetStringMap(key string, optionalDefault ...map[string]any) (map[string]any, error)
GetStringMapString(key string, optionalDefault ...map[string]string) (map[string]string, error)
GetStringSlice(key string, optionalDefault ...[]string) ([]string, error)
GetTime(key string, optionalDefault ...time.Time) (time.Time, error)
FormatString(pattern string, args ...map[string]string) (string, error)
IsSet(string) bool
HasPrefix(prefix string) bool
UnmarshalDefaults(val any, additionalDefaults ...UnmarshalDefaults) error
UnmarshalKey(key string, val any, additionalDefaults ...UnmarshalDefaults) error
}
type EnvProvider ¶
type GosoConf ¶
func NewWithInterfaces ¶
func NewWithInterfaces(envProvider EnvProvider, msis ...map[string]any) GosoConf
type Identity ¶ added in v0.56.0
type Identity struct {
Env string `cfg:"env" json:"env" yaml:"env"`
Name string `cfg:"name" json:"name" yaml:"name"`
Tags Tags `cfg:"tags" json:"tags" yaml:"tags"`
Namespace string `cfg:"namespace,nodecode" json:"-" yaml:"-"`
// contains filtered or unexported fields
}
Identity represents the resolved application identity. It is used throughout gosoline for resource naming and identification.
Configuration structure:
app:
env: production # required
name: myapp # required
tags: # optional
project: ...
family: ...
group: ...
custom: ... # any additional tags
func GetAppIdentity ¶ added in v0.56.0
GetAppIdentity reads the application identity from config.
This function requires:
- "app.name" to be present and non-empty
- "app.env" to be present and non-empty
func (Identity) FormatNamespace ¶ added in v0.56.0
func (*Identity) PadFromConfig ¶ added in v0.56.0
PadFromConfig fills in empty fields of Identity from config.
Behavior:
- If Name is empty, fills from app.name
- If Env is empty, fills from app.env (required, will error if missing/empty)
- If Tags is nil or empty, fills from app.tags
- Existing tag keys are NOT overwritten; only missing keys are added
This method is useful when you have a partially populated Identity (e.g., from struct tag defaults) and want to fill remaining fields.
type MergeOption ¶
type Option ¶
type Option func(cfg *config) error
func WithConfigBytes ¶ added in v0.36.1
func WithConfigFile ¶
func WithConfigFileFlag ¶
func WithConfigMap ¶
func WithConfigMap(settings map[string]any, mergeOptions ...MergeOption) Option
func WithConfigSetting ¶
func WithConfigSetting(key string, settings any, mergeOptions ...MergeOption) Option
func WithEnvKeyPrefix ¶
func WithEnvKeyReplacer ¶
func WithSanitizers ¶
type PostProcessor ¶
type ResourceIdentifier ¶ added in v0.57.0
type ResourceIdentifier struct {
// Env is the environment of the owning application (e.g. "prod", "dev").
// Defaults to app.env when empty.
Env string `cfg:"env"`
// Application is the name of the application that owns the resource.
// Defaults to app.name when empty.
// This maps to {app.name} in naming patterns.
Application string `cfg:"application"`
// Tags are the tags of the owning application used for pattern expansion.
// Missing keys are filled from app.tags; existing keys are preserved.
Tags Tags `cfg:"tags"`
}
ResourceIdentifier identifies a remote resource (e.g. a queue, topic, or stream) by the application that owns it, together with the environment and tags that are used to resolve the resource's naming pattern.
It is designed to be embedded into stream input/output configuration structs so that the config keys are flat (no extra nesting level):
type sqsInputConfiguration struct {
cfg.ResourceIdentifier
QueueId string `cfg:"queue_id"`
...
}
Example YAML:
stream:
input:
my-input:
type: sqs
application: user-service # the APPLICATION that owns the queue
env: prod # optional, defaults to app.env
tags: # optional, merged with app.tags
project: my-project
queue_id: user-events # the resource-specific identifier
The separation between ResourceIdentifier and the resource key (queue_id, topic_id, stream_name, …) is intentional: "application" is unambiguously the owning app name, while the resource key describes what to consume/produce.
To obtain a cfg.Identity suitable for the existing naming functions call ToIdentity() after PadFromConfig().
func (*ResourceIdentifier) PadFromConfig ¶ added in v0.57.0
func (r *ResourceIdentifier) PadFromConfig(config Config) error
PadFromConfig fills empty fields of ResourceIdentifier from global app config.
Behaviour mirrors Identity.PadFromConfig:
- If Application is empty, fills from app.name (required, errors if missing/empty)
- If Env is empty, fills from app.env (required, errors if missing/empty)
- Tags are merged with app.tags; per-resource tag values win over app-level ones
func (ResourceIdentifier) ToIdentity ¶ added in v0.57.0
func (r ResourceIdentifier) ToIdentity() Identity
ToIdentity converts the ResourceIdentifier into a cfg.Identity, mapping Application → Identity.Name. The returned Identity has no Namespace set; call Identity.PadFromConfig to populate it from app.namespace when needed.
type UnmarshalDefaults ¶
func UnmarshalWithDefaultForKey ¶
func UnmarshalWithDefaultForKey(targetKey string, setting any) UnmarshalDefaults
func UnmarshalWithDefaultsFromKey ¶
func UnmarshalWithDefaultsFromKey(sourceKey string, targetKey string) UnmarshalDefaults