modelRT/diagram/anchor_set.go

42 lines
1.2 KiB
Go
Raw Permalink Normal View History

package diagram
import (
"errors"
"fmt"
"sync"
)
// anchorValueOverview define struct of storage all anchor value
var anchorValueOverview sync.Map
// GetAnchorValue define func of get circuit diagram data by componentID
func GetAnchorValue(componentUUID string) (string, error) {
value, ok := diagramsOverview.Load(componentUUID)
if !ok {
return "", fmt.Errorf("can not find anchor value by componentUUID:%s", componentUUID)
}
anchorValue, ok := value.(string)
if !ok {
return "", errors.New("convert to string failed")
}
return anchorValue, nil
}
// UpdateAnchorValue define func of update anchor value by componentUUID and anchor name
func UpdateAnchorValue(componentUUID string, anchorValue string) bool {
_, result := anchorValueOverview.Swap(componentUUID, anchorValue)
return result
}
// StoreAnchorValue define func of store anchor value with componentUUID and anchor name
func StoreAnchorValue(componentUUID string, anchorValue string) {
anchorValueOverview.Store(componentUUID, anchorValue)
return
}
// DeleteAnchorValue define func of delete anchor value with componentUUID
func DeleteAnchorValue(componentUUID string) {
anchorValueOverview.Delete(componentUUID)
return
}