[encoder] implemented encoding.Marshaler for map keys

This commit is contained in:
Aleksandr Petrukhin
2019-04-03 15:41:30 +00:00
parent 1de009706d
commit 6b5a421538
+3 -1
View File
@@ -223,7 +223,9 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT
fmt.Fprintln(g.out, ws+" "+tmpVar+"First := true")
fmt.Fprintln(g.out, ws+" for "+tmpVar+"Name, "+tmpVar+"Value := range "+in+" {")
fmt.Fprintln(g.out, ws+" if "+tmpVar+"First { "+tmpVar+"First = false } else { out.RawByte(',') }")
if keyEnc != "" {
if key.Implements(reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()) {
fmt.Fprintln(g.out, ws+" "+fmt.Sprintf("out.RawText(("+tmpVar+"Name).MarshalText()"+")"))
} else if keyEnc != "" {
fmt.Fprintln(g.out, ws+" "+fmt.Sprintf(keyEnc, tmpVar+"Name"))
} else {
if err := g.genTypeEncoder(key, tmpVar+"Name", tags, indent+2, false); err != nil {