42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package diagram
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
// GraphOverview define struct of storage all circuit diagram topologic data
|
|
var graphOverview sync.Map
|
|
|
|
// GetGraphMap define func of get circuit diagram topologic data by pageID
|
|
func GetGraphMap(pageID int64) (*Graph, error) {
|
|
value, ok := graphOverview.Load(pageID)
|
|
if !ok {
|
|
return nil, fmt.Errorf("can not find graph by pageID:%d", pageID)
|
|
}
|
|
graph, ok := value.(*Graph)
|
|
if !ok {
|
|
return nil, errors.New("convert to graph struct failed")
|
|
}
|
|
return graph, nil
|
|
}
|
|
|
|
// UpdateGrapMap define func of update circuit diagram data by pageID and topologic info
|
|
func UpdateGrapMap(pageID int64, graphInfo *Graph) bool {
|
|
_, result := diagramsOverview.Swap(pageID, graphInfo)
|
|
return result
|
|
}
|
|
|
|
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
|
|
func StoreGraphMap(pageID int64, graphInfo *Graph) {
|
|
diagramsOverview.Store(pageID, graphInfo)
|
|
return
|
|
}
|
|
|
|
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
|
|
func DeleteGraphMap(pageID int64) {
|
|
diagramsOverview.Delete(pageID)
|
|
return
|
|
}
|