structCSVHeader extracts CSV column names from a struct's csv tags.
(v any)
| 12 | |
| 13 | // structCSVHeader extracts CSV column names from a struct's csv tags. |
| 14 | func structCSVHeader(v any) []string { |
| 15 | t := reflect.TypeOf(v) |
| 16 | headers := make([]string, 0, t.NumField()) |
| 17 | for i := 0; i < t.NumField(); i++ { |
| 18 | name := tagName(t.Field(i), "csv") |
| 19 | if name == "" { |
| 20 | continue |
| 21 | } |
| 22 | headers = append(headers, name) |
| 23 | } |
| 24 | return headers |
| 25 | } |
| 26 | |
| 27 | // structCSVRow converts a struct's field values to CSV string values, |
| 28 | // including only fields that have a csv tag. |