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