Skip to content

Commit d42e876

Browse files
committed
Support inline tag in Header function
1 parent a47c010 commit d42e876

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

csvutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func Header(v interface{}, tag string) ([]string, error) {
185185
fields := cachedFields(typeKey{tag, typ})
186186
h := make([]string, len(fields))
187187
for i, f := range fields {
188-
h[i] = f.tag.name
188+
h[i] = f.name
189189
}
190190
return h, nil
191191
}

csvutil_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,36 @@ func TestHeader(t *testing.T) {
661661
tag: "csv",
662662
header: []string{"Y"},
663663
},
664+
{
665+
desc: "inline - simple",
666+
v: &Inline{},
667+
tag: "csv",
668+
header: []string{
669+
"int",
670+
"Bool",
671+
"Uint8",
672+
"float",
673+
"prefix-STR",
674+
"prefix-int",
675+
"prefix-Bool",
676+
"prefix-Uint8",
677+
"prefix-float",
678+
"top-string",
679+
"STR",
680+
},
681+
},
682+
{
683+
desc: "inline - chain",
684+
v: &Inline5{},
685+
tag: "csv",
686+
header: []string{"AS", "AAA", "S", "A"},
687+
},
688+
{
689+
desc: "inline - top level",
690+
v: &Inline8{},
691+
tag: "csv",
692+
header: []string{"AA"},
693+
},
664694
{
665695
desc: "nil ptr of TypeF",
666696
v: nilPtr,

0 commit comments

Comments
 (0)