MCPcopy
hub / github.com/moonD4rk/HackBrowserData / structCSVRow

Function structCSVRow

output/reflect.go:29–40  ·  view source on GitHub ↗

structCSVRow converts a struct's field values to CSV string values, including only fields that have a csv tag.

(v any)

Source from the content-addressed store, hash-verified

27// structCSVRow converts a struct's field values to CSV string values,
28// including only fields that have a csv tag.
29func 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".

Callers 2

TestStructCSVRowFunction · 0.85
csvRowMethod · 0.85

Calls 2

tagNameFunction · 0.85
fieldToStringFunction · 0.85

Tested by 1

TestStructCSVRowFunction · 0.68