MCPcopy
hub / github.com/wavetermdev/waveterm / SetRTInfo

Function SetRTInfo

pkg/wstore/wstore_rtinfo.go:84–125  ·  view source on GitHub ↗

SetRTInfo merges the provided info map into the ObjRTInfo for the given ORef. Only updates fields that exist in the ObjRTInfo struct. Removes fields that have nil values.

(oref waveobj.ORef, info map[string]any)

Source from the content-addressed store, hash-verified

82// Only updates fields that exist in the ObjRTInfo struct.
83// Removes fields that have nil values.
84func SetRTInfo(oref waveobj.ORef, info map[string]any) {
85 rtInfoMutex.Lock()
86 defer rtInfoMutex.Unlock()
87
88 rtInfo, exists := rtInfoStore[oref]
89 if !exists {
90 rtInfo = &waveobj.ObjRTInfo{}
91 rtInfoStore[oref] = rtInfo
92 }
93
94 rtInfoValue := reflect.ValueOf(rtInfo).Elem()
95 rtInfoType := rtInfoValue.Type()
96
97 // Build a map of json tags to field indices for quick lookup
98 jsonTagToField := make(map[string]int)
99 for i := 0; i < rtInfoType.NumField(); i++ {
100 field := rtInfoType.Field(i)
101 jsonTag := field.Tag.Get("json")
102 if jsonTag != "" {
103 // Remove omitempty and other options
104 tagParts := strings.Split(jsonTag, ",")
105 if len(tagParts) > 0 && tagParts[0] != "" {
106 jsonTagToField[tagParts[0]] = i
107 }
108 }
109 }
110
111 // Merge the info map into the struct
112 for key, value := range info {
113 fieldIndex, exists := jsonTagToField[key]
114 if !exists {
115 continue // Skip keys that don't exist in the struct
116 }
117
118 fieldValue := rtInfoValue.Field(fieldIndex)
119 if !fieldValue.CanSet() {
120 continue
121 }
122
123 setFieldValue(fieldValue, value)
124 }
125}
126
127// GetRTInfo returns the ObjRTInfo for the given ORef, or nil if not found
128func GetRTInfo(oref waveobj.ORef) *waveobj.ObjRTInfo {

Callers 3

SetRTInfoCommandMethod · 0.92
setManifestMetadataMethod · 0.92
clearSchemasMethod · 0.92

Calls 3

setFieldValueFunction · 0.85
TypeMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected