package diagram import ( "errors" "fmt" "sync" cmap "github.com/orcaman/concurrent-map/v2" ) // DiagramsOverview define struct of storage all circuit diagram data var diagramsOverview sync.Map // GetComponentMap define func of get circuit diagram data by global uuid func GetComponentMap(uuid string) (*cmap.ConcurrentMap[string, any], error) { value, ok := diagramsOverview.Load(uuid) if !ok { return nil, fmt.Errorf("can not find graph by global uuid:%s", uuid) } paramsMap, ok := value.(*cmap.ConcurrentMap[string, any]) if !ok { return nil, errors.New("convert to component map struct failed") } return paramsMap, nil } // UpdateComponentMap define func of update circuit diagram data by global uuid and component info func UpdateComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) bool { _, result := diagramsOverview.Swap(uuid, componentInfo) return result } // StoreComponentMap define func of store circuit diagram data with global uuid and component info func StoreComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) { diagramsOverview.Store(uuid, componentInfo) return }