Move separator defaulting back into Tag.

This commit is contained in:
Alec Thomas
2018-06-13 22:58:53 +10:00
parent ecf21e4cc9
commit 662ace41c5
3 changed files with 7 additions and 9 deletions
-6
View File
@@ -234,9 +234,6 @@ func mapDecoder(d *Registry) MapperFunc {
} }
el := target.Type() el := target.Type()
sep := ctx.Value.Tag.Sep sep := ctx.Value.Tag.Sep
if sep == 0 {
sep = '='
}
token := ctx.Scan.PopValue("map") token := ctx.Scan.PopValue("map")
parts := SplitEscaped(token, sep) parts := SplitEscaped(token, sep)
if len(parts) != 2 { if len(parts) != 2 {
@@ -267,9 +264,6 @@ func sliceDecoder(d *Registry) MapperFunc {
return func(ctx *DecodeContext, target reflect.Value) error { return func(ctx *DecodeContext, target reflect.Value) error {
el := target.Type().Elem() el := target.Type().Elem()
sep := ctx.Value.Tag.Sep sep := ctx.Value.Tag.Sep
if sep == 0 {
sep = ','
}
var childScanner *Scanner var childScanner *Scanner
if ctx.Value.Flag != nil { if ctx.Value.Flag != nil {
// If decoding a flag, we need an argument. // If decoding a flag, we need an argument.
-3
View File
@@ -27,9 +27,6 @@ func JSON(r io.Reader) (ResolverFunc, error) {
return "", nil return "", nil
} }
sep := flag.Tag.Sep sep := flag.Tag.Sep
if sep == 0 {
sep = ','
}
value, err := jsonDecodeValue(sep, raw) value, err := jsonDecodeValue(sep, raw)
if err != nil { if err != nil {
return "", err return "", err
+7
View File
@@ -130,6 +130,13 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
t.Hidden = t.Has("hidden") t.Hidden = t.Has("hidden")
t.Format, _ = t.Get("format") t.Format, _ = t.Get("format")
t.Sep, _ = t.GetRune("sep") t.Sep, _ = t.GetRune("sep")
if t.Sep == 0 {
if fv.Kind() == reflect.Map {
t.Sep = '='
} else {
t.Sep = ','
}
}
t.PlaceHolder, _ = t.Get("placeholder") t.PlaceHolder, _ = t.Get("placeholder")
if t.PlaceHolder == "" { if t.PlaceHolder == "" {
t.PlaceHolder = strings.ToUpper(dashedString(fv.Type().Name())) t.PlaceHolder = strings.ToUpper(dashedString(fv.Type().Name()))