package diagram import ( "errors" "fmt" "sync" ) // graphOverview define struct of storage all circuit diagram topologic data var graphOverview sync.Map // PrintGrapMap define func of print circuit diagram topologic info data func PrintGrapMap() { graphOverview.Range(func(key, value interface{}) bool { fmt.Println(key, value) return true }) } // 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 := graphOverview.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) { graphOverview.Store(pageID, graphInfo) return } // DeleteGraphMap define func of delete circuit diagram topologic data with pageID func DeleteGraphMap(pageID int64) { graphOverview.Delete(pageID) return }