MCPcopy
hub / github.com/tinyauthapp/tinyauth / walkAndBuild

Function walkAndBuild

gen/gen.go:15–38  ·  view source on GitHub ↗
(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,
)

Source from the content-addressed store, hash-verified

13}
14
15func 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}

Callers 4

generateMarkdownFunction · 0.85
buildMdMapEntryFunction · 0.85
generateExampleEnvFunction · 0.85
buildEnvMapEntryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected