-
Notifications
You must be signed in to change notification settings - Fork 211
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
How to unmarshal map[string]map[string]interface{}
#337
Comments
To give more context the key of
|
I also tried:
but it prints But maybe this is solved by #335 ? |
I look into the implementation of unmarshal and find that it seems go-toml do not support type Config struct {
Name string
Python string
ProjectDir string
Dependencies map[string]string
ContainerArgs map[string]string
Aliases map[string]struct {
Cmd string
Ports []int
}
}
type RawConfig struct {
Tool struct {
Pydockenv *Config
}
}
doc := []byte(`
[tool.pydockenv]
name = "jupyter-notebook"
python = "3.7.4"
[tool.pydockenv.dependencies]
jupyter = "==1.0.0"
[tool.pydockenv.aliases]
[tool.pydockenv.aliases.notebook]
cmd = "jupyter notebook --allow-root --ip=0.0.0.0 --port=8888"
ports = [8888]`)
rawConfig := RawConfig{}
if err := toml.Unmarshal(doc, &rawConfig); err != nil {
fmt.Println(err)
}
fmt.Println("name=", rawConfig.Tool.Pydockenv.Name)
fmt.Println("aliases=", rawConfig.Tool.Pydockenv.Aliases) And it works in my environment(with latest version v1.6.0). Just change |
Thanks a lot @AllenX2018! This is exactly what I was looking for! |
Awesome, glad you got unblocked! Thank you @AllenX2018. Unfortunately yes, the diagnostic is correct: support for |
Describe the bug
This is more a question. How can I properly unmarshal a toml as the following?
where there's no fixed structure for
tool.pydockenv.aliases
.To Reproduce
This doesn't work as it raises:
at the line with where it should print the name.
If I change it to:
then it assigns the
name
correctly, so I guess something is wrong in theAliases
field ofConfig
. Here's the output:By using the original
doc
value, I also tried to change theConfig
as follows:but the aliases is not there:
Versions
The text was updated successfully, but these errors were encountered: