From 2d0186276a09b0d6987dd50e4833e64b4ac4d7f0 Mon Sep 17 00:00:00 2001 From: hori-ryota Date: Mon, 27 Jun 2022 16:24:59 +0900 Subject: [PATCH] fix: nexted prefix order with inline --- cache.go | 2 +- example_encoder_test.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cache.go b/cache.go index 7c5edd0..2e4627d 100644 --- a/cache.go +++ b/cache.go @@ -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 diff --git a/example_encoder_test.go b/example_encoder_test.go index 31fb16c..f9c8eaf 100644 --- a/example_encoder_test.go +++ b/example_encoder_test.go @@ -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 { @@ -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, }, } @@ -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() {