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)
| 82 | // Only updates fields that exist in the ObjRTInfo struct. |
| 83 | // Removes fields that have nil values. |
| 84 | func 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 |
| 128 | func GetRTInfo(oref waveobj.ORef) *waveobj.ObjRTInfo { |
no test coverage detected