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

Ordered Array when parsing configuration values #103

Open
ph opened this issue Apr 10, 2018 · 1 comment
Open

Ordered Array when parsing configuration values #103

ph opened this issue Apr 10, 2018 · 1 comment
Labels

Comments

@ph
Copy link
Contributor

ph commented Apr 10, 2018

Let's say we want to create a mapping table to replace values from an integer to a string, this is currently not possible with the current config type casting.

Example:

potato:
  1: "abc"
  2: "oko"
  50: "noo"

When loaded from ucfg, the map get converted into an slice.

potato:
  - "abc"
  - "oko"
  - "noo"

Even if you escape the key as a string, ucfg will try to convert the value to an integer and succeed.

potato:
  "1": "abc"
  "2": "oko"
  "50": "noo"

potato:
  - "abc"
  - "oko"
  - "noo"

After discussing with @urso on zoom we would like to support the following use case to reduce the size of the configuration and the verbosity of usings keys in the yaml.

config:
  2: v1
  5: v2
config:
  - a
  - b
cfg *common.Config // table = map + array
var m map[string]string
var a []string

cfg.Unpack(&m) // map[2: v1, 5: v2]
cfg.Unpack(&a) // [a, b]

cfg.Unpack(&m) // map[2: v1, 5: v2, 0: a, 1: b]
cfg.Unpack(&a) // [a, b]
@ph
Copy link
Contributor Author

ph commented Apr 10, 2018

@urso updated with our example from our talk.

@ph ph added the bug label Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant