Use Nested and Inline structs
mastercsvutil supports nested or embedded structs.
- Embedded structs: Fields are flattened into the CSV.
- Inline tags: Use the
csv:",inline"tag to flatten a struct. You can also provide a prefix (e.g.,csv:"prefix_,inline") to namespace the underlying fields in the CSV columns.
type Address struct {
Street string `csv:"street"`
City string `csv:"city"`
}
type User struct {
Name string `csv:"name"`
Address Address `csv:",inline"` // Flattened
HomeAddress Address `csv:"home_,inline"` // Prefixed: home_street, home_city
WorkAddress Address `csv:"work_,inline"` // Prefixed: work_street, work_city
Age int `csv:"age,omitempty"`
}