(parent reflect.Type, parentValue reflect.Value, parentPath string, entries *[]T, buildEntry func(child reflect.StructField, childValue reflect.Value, parentPath string, entries *[]T), buildMap func(child reflect.StructField, parentPath string, entries *[]T), buildChildPath func(parentPath string, childName string) string, )
| 13 | } |
| 14 | |
| 15 | func walkAndBuild[T any](parent reflect.Type, parentValue reflect.Value, |
| 16 | parentPath string, entries *[]T, |
| 17 | buildEntry func(child reflect.StructField, childValue reflect.Value, parentPath string, entries *[]T), |
| 18 | buildMap func(child reflect.StructField, parentPath string, entries *[]T), |
| 19 | buildChildPath func(parentPath string, childName string) string, |
| 20 | ) { |
| 21 | for i := 0; i < parent.NumField(); i++ { |
| 22 | field := parent.Field(i) |
| 23 | fieldType := field.Type |
| 24 | fieldValue := parentValue.Field(i) |
| 25 | |
| 26 | switch fieldType.Kind() { |
| 27 | case reflect.Struct: |
| 28 | childPath := buildChildPath(parentPath, field.Name) |
| 29 | walkAndBuild[T](fieldType, fieldValue, childPath, entries, buildEntry, buildMap, buildChildPath) |
| 30 | case reflect.Map: |
| 31 | buildMap(field, parentPath, entries) |
| 32 | case reflect.Bool, reflect.String, reflect.Slice, reflect.Int: |
| 33 | buildEntry(field, fieldValue, parentPath, entries) |
| 34 | default: |
| 35 | slog.Info("unknown type", "type", fieldType.Kind()) |
| 36 | } |
| 37 | } |
| 38 | } |
no outgoing calls
no test coverage detected