ardanlabs/conf

Problems with field delimiter (comma)

BrunoPereira opened this issue · 6 comments

Hi
I was experimenting with the latest version and found out that I can't use []string ( or []int )

I have a structure like this:
type ConfigOptions struct {
auxEndpoints []string conf:"default:127.0.0.1:200,127.0.0.1:829"
}

The problem is that comma is used to separate fields, so the "processField" can't recognize that last value and processes it as a field.

I suggest changing it to a semicolon.
Ex:
type ConfigOptions struct {
auxEndpoints []string conf:"default:127.0.0.1:200,127.0.0.1:829;short:d;help:test"
}

If you agree with this, I have a fork with the fix....

The reflect package defines the format. That being said, I don’t remember how custom this may be. It’s still early in the packages lifetime. I will look at this today.

The reflect defines it correctly, the problem is here:
`
func parseTag(tagStr string) (fieldOptions, error) {
var f fieldOptions
if tagStr == "" {
return f, nil
}

tagParts := strings.Split(tagStr, ",")

`

fields.go, line 146
we can't have a default like the one I mentioned on the 1st post

Ok, let me look at this. I am a bit worried about backward compatibility. Let's see.

What is we did this?

auxEndpoints []string conf:"default:127.0.0.1:200;127.0.0.1:829,short:d,help:test

Keep the comma for backward compatibility. Use the semicolon to separate the parts of the string?

Added the fix and tests to use the semicolon (;) to separate values in a collection. This minimizes the breaking change so a smaller number of projects.

Updated the documentation about using semicolon to separate values in a collection.