UpdateSliceTable updates given Table with data from the given slice of structs, which must be the same type as used to configure the table
(st any, dt *Table)
| 57 | // UpdateSliceTable updates given Table with data from the given slice |
| 58 | // of structs, which must be the same type as used to configure the table |
| 59 | func UpdateSliceTable(st any, dt *Table) { |
| 60 | npv := reflectx.NonPointerValue(reflect.ValueOf(st)) |
| 61 | eltyp := reflectx.NonPointerType(npv.Type().Elem()) |
| 62 | |
| 63 | nr := npv.Len() |
| 64 | dt.SetNumRows(nr) |
| 65 | for ri := 0; ri < nr; ri++ { |
| 66 | for i := 0; i < eltyp.NumField(); i++ { |
| 67 | f := eltyp.Field(i) |
| 68 | switch f.Type.Kind() { |
| 69 | case reflect.Float32: |
| 70 | dt.SetFloat(f.Name, ri, float64(npv.Index(ri).Field(i).Interface().(float32))) |
| 71 | case reflect.Float64: |
| 72 | dt.SetFloat(f.Name, ri, float64(npv.Index(ri).Field(i).Interface().(float64))) |
| 73 | case reflect.String: |
| 74 | dt.SetString(f.Name, ri, npv.Index(ri).Field(i).Interface().(string)) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
nothing calls this directly
no test coverage detected