-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (44 loc) · 1.36 KB
/
main.go
File metadata and controls
55 lines (44 loc) · 1.36 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
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/Azhovan/rigging"
"github.com/Azhovan/rigging/sourceenv"
"github.com/Azhovan/rigging/sourcefile"
)
func main() {
ctx := context.Background()
fmt.Println("=== Configuration Library Example ===")
fmt.Println()
// Create a loader with multiple sources
// Sources are processed in order: file first, then environment variables
// Environment variables will override file values
// Try to find config.yaml in current directory or examples/basic directory
configPath := "config.yaml"
if _, err := os.Stat(configPath); os.IsNotExist(err) {
configPath = "examples/basic/config.yaml"
}
loader := rigging.NewLoader[AppConfig]().
WithSource(sourcefile.New(configPath, sourcefile.Options{
Required: false, // Make file optional for demo purposes
})).
WithSource(sourceenv.New(sourceenv.Options{
Prefix: "APP_", // Only read env vars starting with APP_
})).
WithValidator(rigging.ValidatorFunc[AppConfig](customValidator)).
Strict(false) // Allow unknown configuration keys for demo
printLoadPlan()
// Load the configuration
cfg, err := loader.Load(ctx)
if err != nil {
log.Fatalf("Failed to load configuration: %v\n", err)
}
fmt.Println("✓ Configuration loaded successfully!")
fmt.Println()
printLoadedConfig(cfg)
printProvenance(cfg)
printEffectiveDumps(cfg)
printNextSteps()
}