harveyaot / gcfg

Automatically exported from code.google.com/p/gcfg
Other
0 stars 0 forks source link

dashes in field names are always converted to underscores #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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