-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
Unable to read configuration from yaml file:
main.go
package main
import (
"log"
"github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigdotenv"
"github.com/cristalhq/aconfig/aconfigyaml"
)
type StringType string
type NestedStruct struct {
Key string
}
type NestedArr struct {
Enabled bool
Str StringType
NestedStruct NestedStruct `yaml:"nested_struct"`
Data map[string]any
}
type Items struct {
Arrs []NestedArr
}
type MyConfig struct {
Items Items `yaml:"items"`
}
func main() {
var cfg MyConfig
loader := aconfig.LoaderFor(&cfg, aconfig.Config{
Files: []string{"config.yaml"},
FileDecoders: map[string]aconfig.FileDecoder{
".yaml": aconfigyaml.New(),
".yml": aconfigyaml.New(),
".env": aconfigdotenv.New(),
},
})
if err := loader.Load(); err != nil {
log.Fatalf("could not load config: %v", err)
}
log.Printf("Config: %+v", cfg)
}
config.yaml
items:
arrs:
- enabled: true
str: asdasd
nest_struct:
key: value
data:
key: value
bool: true
Errors:
- 2025/03/11 09:02:24 could not load config: load config: load files: provided value type do not match struct field type (main.StringType and string)
- 2025/03/11 09:01:44 could not load config: load config: load files: no such field "Nested_struct" in struct
Metadata
Metadata
Assignees
Labels
No labels