Skip to content

Commit

Permalink
Merge pull request #54 from hori-ryota/fix-nested-prefix-order
Browse files Browse the repository at this point in the history
fix: nexted prefix order with inline
  • Loading branch information
jszwec authored Jun 29, 2022
2 parents 7c7652d + 2d01862 commit 2b7b86b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func buildFields(k typeKey) fields {
continue
}
if f.tag.prefix != "" {
tag.prefix += f.tag.prefix
tag.prefix = f.tag.prefix + tag.prefix
}

ft := sf.Type
Expand Down
15 changes: 10 additions & 5 deletions example_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ func ExampleEncoder_EncodeHeader() {
}

func ExampleEncoder_Encode_inline() {
type Owner struct {
Name string `csv:"name"`
}

type Address struct {
Street string `csv:"street"`
City string `csv:"city"`
Owner Owner `csv:"owner_,inline"`
}

type User struct {
Expand All @@ -132,9 +137,9 @@ func ExampleEncoder_Encode_inline() {
users := []User{
{
Name: "John",
Address: Address{"Washington", "Boston"},
HomeAddress: Address{"Boylston", "Boston"},
WorkAddress: Address{"River St", "Cambridge"},
Address: Address{"Washington", "Boston", Owner{"Steve"}},
HomeAddress: Address{"Boylston", "Boston", Owner{"Steve"}},
WorkAddress: Address{"River St", "Cambridge", Owner{"Steve"}},
Age: 26,
},
}
Expand All @@ -147,8 +152,8 @@ func ExampleEncoder_Encode_inline() {
fmt.Printf("%s\n", b)

// Output:
// name,street,city,home_address_street,home_address_city,work_address_street,work_address_city,age
// John,Washington,Boston,Boylston,Boston,River St,Cambridge,26
// name,street,city,owner_name,home_address_street,home_address_city,home_address_owner_name,work_address_street,work_address_city,work_address_owner_name,age
// John,Washington,Boston,Steve,Boylston,Boston,Steve,River St,Cambridge,Steve,26
}

func ExampleEncoder_Register() {
Expand Down

0 comments on commit 2b7b86b

Please sign in to comment.