Quantcast
Channel: User Schwern - Stack Overflow
Viewing all articles
Browse latest Browse all 581

Comment by Schwern on What's the standard Go approach to mapping values from one structure to another

$
0
0
If you just want standard string formatting for each type, switch field.Kind() ... can be replaced with record = append(record, fmt.Sprintf("%v", field)). for i := range inputs { value := reflect.ValueOf(inputs[i]) is better written as for _, input { value := reflect.ValueOf(input). If reflect.ValueOf proves to be a performance issue, I doubt it, you could instead write a switch matching each string input to a struct field. If you want to get extra fancy, implement fmt.Formatter for SalesData

Viewing all articles
Browse latest Browse all 581

Trending Articles