MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / getFieldValueWithReflection

Function getFieldValueWithReflection

tsunami/ui/table.go:68–92  ·  view source on GitHub ↗

Helper to extract field value from struct/map using reflection

(item any, key string)

Source from the content-addressed store, hash-verified

66
67// Helper to extract field value from struct/map using reflection
68func getFieldValueWithReflection(item any, key string) any {
69 if item == nil {
70 return nil
71 }
72
73 // Handle map[string]any
74 if m, ok := item.(map[string]any); ok {
75 return m[key]
76 }
77
78 // Handle struct via reflection
79 v := reflect.ValueOf(item)
80 if v.Kind() == reflect.Ptr {
81 v = v.Elem()
82 }
83 if v.Kind() != reflect.Struct {
84 return nil
85 }
86
87 field := v.FieldByName(key)
88 if !field.IsValid() {
89 return nil
90 }
91 return field.Interface()
92}
93
94// Generic helper to extract field value using either AccessorFn or reflection
95func getFieldValue[T any](row T, rowIdx int, col TableColumn[T]) any {

Callers 1

getFieldValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected