-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_feeders.go
More file actions
89 lines (78 loc) · 3.61 KB
/
config_feeders.go
File metadata and controls
89 lines (78 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package modular
import (
"github.com/GoCodeAlone/modular/feeders"
)
// Feeder defines the interface for configuration feeders that provide configuration data.
type Feeder interface {
// Feed gets a struct and feeds it using configuration data.
Feed(structure any) error
}
// ConfigFeeders provides a default set of configuration feeders for common use cases
var ConfigFeeders = []Feeder{
feeders.NewEnvFeeder(),
}
// ComplexFeeder extends the basic Feeder interface with additional functionality for complex configuration scenarios
type ComplexFeeder interface {
Feeder
FeedKey(string, any) error
}
// InstanceAwareFeeder provides functionality for feeding multiple instances of the same configuration type
type InstanceAwareFeeder interface {
ComplexFeeder
// FeedInstances feeds multiple instances from a map[string]ConfigType
FeedInstances(instances any) error
}
// VerboseAwareFeeder provides functionality for verbose debug logging during configuration feeding
type VerboseAwareFeeder interface {
// SetVerboseDebug enables or disables verbose debug logging
SetVerboseDebug(enabled bool, logger interface{ Debug(msg string, args ...any) })
}
// VerboseLogger provides a minimal logging interface to avoid circular dependencies
type VerboseLogger interface {
Debug(msg string, args ...any)
}
// ModuleAwareFeeder provides functionality for feeders that can receive module context
// during configuration feeding. This allows feeders to customize behavior based on
// which module's configuration is being processed.
type ModuleAwareFeeder interface {
Feeder
// FeedWithModuleContext feeds configuration with module context information.
// The moduleName parameter provides the name of the module whose configuration
// is being processed, allowing the feeder to customize its behavior accordingly.
FeedWithModuleContext(structure any, moduleName string) error
}
// PrioritizedFeeder extends the Feeder interface with priority control.
// Feeders with higher priority values will be applied later, allowing them to override
// values set by lower priority feeders. This enables explicit control over configuration
// precedence when using multiple feeders.
//
// Default priority is 0. When feeders have the same priority, they are applied in
// the order they were added (maintaining backward compatibility).
//
// All standard feeders implement this interface and provide a WithPriority() method
// for setting the priority value using the builder pattern:
//
// feeders.NewYamlFeeder("config.yaml").WithPriority(100) // High priority
// feeders.NewEnvFeeder().WithPriority(50) // Lower priority
//
// In this example, YAML configuration will override environment variables because
// it has higher priority.
//
// Note: WithPriority() is not part of this interface because it's a builder method
// that returns the concrete feeder type for method chaining. All standard feeders
// (EnvFeeder, YamlFeeder, JSONFeeder, TomlFeeder, DotEnvFeeder, AffixedEnvFeeder,
// TenantAffixedEnvFeeder) provide this method with a consistent signature:
//
// WithPriority(priority int) *FeederType
type PrioritizedFeeder interface {
Feeder
// Priority returns the priority value for this feeder.
// Higher values mean higher priority (applied later, overrides earlier feeders).
Priority() int
}
// InstancePrefixFunc is a function that generates a prefix for an instance key
type InstancePrefixFunc = feeders.InstancePrefixFunc
// NewInstanceAwareEnvFeeder creates a new instance-aware environment variable feeder
func NewInstanceAwareEnvFeeder(prefixFunc InstancePrefixFunc) InstanceAwareFeeder {
return feeders.NewInstanceAwareEnvFeeder(prefixFunc)
}