Skip to content

Panic when parse toml slice #117

@bynil

Description

@bynil

POC:

func main() {
	type MyConfig struct {
		Slice []struct {
			A int
		} `json:"slice" toml:"slice"`
	}

	var cfg MyConfig
	loader := aconfig.LoaderFor(&cfg, aconfig.Config{
		// feel free to skip some steps :)
		// SkipDefaults: true,
		// SkipFiles:    true,
		// SkipEnv:      true,
		// SkipFlags:    true,
		EnvPrefix:  "APP",
		FlagPrefix: "app",
		Files:      []string{"config.toml"},
		FileDecoders: map[string]aconfig.FileDecoder{
			// from `aconfigyaml` submodule
			// see submodules in repo for more formats
			".toml": aconfigtoml.New(),
		},
	})

	if err := loader.Load(); err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", cfg)
}

config.toml file:

[[slice]]
A = 5

Result:

panic: []map[string]interface {} [map[A:5]]
github.com/cristalhq/aconfig@v0.16.8/reflection.go:190 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions