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

dashes in field names are always converted to underscores #9

Closed
GoogleCodeExporter opened this issue Feb 2, 2016 · 3 comments
Closed

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Add a field in a config Struct with the name `SomeKey`
2. Add the tag `gcfg:"some-key"` to the field

What is the expected output? What do you see instead?
Expect "some-key" in config to be filled in SomeKey, instead I get the error 

invalid variable: section "foo" variable "some-key"

What I gather from the source code is that it *always* replaces dashes with 
hyphens before anything else, so it is looking for a field `Some_Key` instead 
of `SomeKey`, and is completely ignoring the tag I added to the field. So 
instead the code should first look for a tag, and if and only if no tag exists, 
replace dashes with underscores.

What version of the product are you using? On what operating system?
Go1.3.1 on CentOS 7 x64

Original issue reported on code.google.com by rpk...@gmail.com on 2 Nov 2014 at 7:32

@GoogleCodeExporter
Copy link
Author

Thanks for the report, but I can't reproduce the issue. Actually there is an 
example in the docs showing that dashes specified in tags work: 
http://godoc.org/code.google.com/p/gcfg#example-ReadStringInto--Tags

Can you share a runnable code sample that demonstrates the error?

While the readability of the code could be improved, the '-' => '_' 
substitution only matters for fields where there is no name specified in a tag.

Original comment by speter....@gmail.com on 3 Nov 2014 at 4:00

@GoogleCodeExporter
Copy link
Author

I just tried to reproduce the error I got yesterday and I can't seem to get it 
to fail any more :/
I did update the package before I tested, so maybe it was fixed?

In any case, this issue can be closed.
Thanks for your time!

Original comment by rpk...@gmail.com on 3 Nov 2014 at 7:30

@GoogleCodeExporter
Copy link
Author

I didn't go through the diffs in detail but I don't recall any relevant changes 
(unless you were using a version prior to tags support). At least the 
example-test has been there since the initial implementation. What occurred to 
me is that the error could happen if the field is not exported, but that is to 
be expected.

Anyway feel free to reopen in case you encounter it again.

Original comment by speter....@gmail.com on 3 Nov 2014 at 9:29

  • Changed state: WorksForMe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant