-
-
Notifications
You must be signed in to change notification settings - Fork 529
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 use IsDefined with array of tables? #169
Comments
Yeah, there's no way at the moment. The API doesn't offer a clear way to add this feature, either. Super hacky strawman proposal: Probably we should add a new method instead. I'm not even sure what the API should be, though. @BurntSushi any thoughts? |
I don't have any strong opinions, but it would be nice to make |
@BurntSushi what do you expect, though? |
I suppose I'd expect it to return true because there exists a |
If you look at it that way, it certainly is not well defined. Suppose I walk over
Then having an index into array would tell us which one to look at. I am thinking of what @cespare said earlier:
If I try that, it doesn't work for me now, but it would certainly be more than good enough. More info: When searching for some issue about using Cgo I stumbled upon a post which describes when to use I was not aware of this distinction, so I could simply convert my struct like so:
and then with the above for loop I can say:
So if you feel like not bothering with this, I am more than OK with closing this issue and I'll change my code to work this way. |
I don't know if this is an issue or just me not knowing how to properly call it, so I apologize if I opened a new issue which is not an issue at all.
I have a config file where I want to specify one section several times:
Here's a complete example:
This returns "not defined". How can one use IsDefined() in this case? Is it possible at all?
I have tried different usages as the commend above IsDefined() in decode.go says:
but nothing works.
My real example is a bit more complex, and config parser works as expected when I just blindly assign values from config struct, but I'd like to only do that when something is present in the config file. I can't rely on what Keys() returns as that one is not specific enough, but it at least shows that the keys are there as expected (as the example prints it).
If I look at what is going on in decode.go and compare working (where I use just a simple struct) vs. non-working example, when it works, it gets this type:
map[string]interface {}
But for this failing example it gets:
[]map[string]interface {}
And then it fails here on second (might be third - depends how it gets called obviouslly) loop iteration:
if hash, ok = hashOrVal.(map[string]interface{}); !ok
The text was updated successfully, but these errors were encountered: