Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for native map syntax in files #99

Closed
vfaronov opened this issue Aug 14, 2021 · 0 comments · Fixed by #101
Closed

No support for native map syntax in files #99

vfaronov opened this issue Aug 14, 2021 · 0 comments · Fixed by #101
Labels
feature New feature or request

Comments

@vfaronov
Copy link

Given the following toy.json:

{
  "options": {
    "foo": 0.4,
    "bar": 0.25
  }
}

and the following program:

package main

import (
	"fmt"

	"github.com/cristalhq/aconfig"
)

func main() {
	var cfg struct {
		Options map[string]float64
	}
	loader := aconfig.LoaderFor(&cfg, aconfig.Config{
		Files: []string{"toy.json"},
	})
	err := loader.Load()
	fmt.Printf("%v\n%+v\n", err, cfg)
}

I expect the program to print:

<nil>
{Options:map[bar:0.25 foo:0.4]}

But instead, it prints:

aconfig: cannot load config: loading files: incorrect map value "0.25 foo:0.4]": strconv.ParseFloat: parsing "0.25 foo:0.4]": invalid syntax
{Options:map[]}

The desired output is achieved if I replace toy.json with:

{
  "options": "foo:0.4,bar:0.25"
}

It would be much more convenient to be able to specify maps with the config language’s native map syntax.

@cristaloleg cristaloleg added the feature New feature or request label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants