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

How to Decode with default values in []struct? #187

Closed
zerolyd opened this issue Aug 10, 2017 · 1 comment
Closed

How to Decode with default values in []struct? #187

zerolyd opened this issue Aug 10, 2017 · 1 comment

Comments

@zerolyd
Copy link

zerolyd commented Aug 10, 2017

eg:

type Server struct {
    Url     string
    Port    int
}

type Host struct {
    Servers []Server
}

var blob = `
[Host]
[[Servers]]
Url = "http://google.com"

[[Servers]]
Url = "http://github.com"
`

How to Decode with all Servers Port = 80?

@cespare
Copy link
Collaborator

cespare commented Aug 10, 2017

Unfortunately, because of the array, there's no good way to do this (because of #169 even meta.IsDefined doesn't help). So you're left with something like https://play.golang.org/p/DJ76rVVE5a for now. Sorry!

@cespare cespare closed this as completed Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants