structCSVRow converts a struct's field values to CSV string values, including only fields that have a csv tag.
(v any)
| 27 | // structCSVRow converts a struct's field values to CSV string values, |
| 28 | // including only fields that have a csv tag. |
| 29 | func structCSVRow(v any) []string { |
| 30 | val := reflect.ValueOf(v) |
| 31 | t := val.Type() |
| 32 | row := make([]string, 0, t.NumField()) |
| 33 | for i := 0; i < t.NumField(); i++ { |
| 34 | if tagName(t.Field(i), "csv") == "" { |
| 35 | continue |
| 36 | } |
| 37 | row = append(row, fieldToString(val.Field(i))) |
| 38 | } |
| 39 | return row |
| 40 | } |
| 41 | |
| 42 | // tagName extracts the tag value for the given key from a struct field. |
| 43 | // Uses Lookup (not Get) to distinguish "no tag" from "empty tag". |