modelRT/diagram/component_set.go

42 lines
1.2 KiB
Go

package diagram
import (
"errors"
"fmt"
"sync"
)
// 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) (map[string]interface{}, error) {
value, ok := diagramsOverview.Load(uuid)
if !ok {
return nil, fmt.Errorf("can not find graph by global uuid:%s", uuid)
}
paramsMap, ok := value.(map[string]interface{})
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 map[string]interface{}) 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 map[string]interface{}) {
diagramsOverview.Store(uuid, componentInfo)
return
}
// DeleteComponentMap define func of delete circuit diagram data with global uuid
func DeleteComponentMap(uuid string) {
diagramsOverview.Delete(uuid)
return
}