modelRT/diagram/anchor_set.go

42 lines
1.1 KiB
Go
Raw 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 global uuid
func GetAnchorValue(uuid string) (string, error) {
value, ok := diagramsOverview.Load(uuid)
if !ok {
return "", fmt.Errorf("can not find anchor value by global uuid:%s", uuid)
}
anchorValue, ok := value.(string)
if !ok {
return "", errors.New("convert to string failed")
}
return anchorValue, nil
}
// UpdateAnchorValue define func of update anchor value by global uuid and anchor name
func UpdateAnchorValue(uuid string, anchorValue string) bool {
_, result := anchorValueOverview.Swap(uuid, anchorValue)
return result
}
// StoreAnchorValue define func of store anchor value with global uuid and anchor name
func StoreAnchorValue(uuid string, anchorValue string) {
anchorValueOverview.Store(uuid, anchorValue)
return
}
// DeleteAnchorValue define func of delete anchor value with global uuid
func DeleteAnchorValue(uuid string) {
anchorValueOverview.Delete(uuid)
return
}