flowmgr.go 640 B

123456789101112131415161718192021222324252627282930313233343536
  1. //@File flowmgr.go
  2. //@Time 2022/05/13
  3. //@Author #Suyghur,
  4. package mgr
  5. import (
  6. "sync"
  7. "ylink/flowsrv/rpc/pb"
  8. )
  9. type flowManager struct {
  10. flowMap map[string]pb.Flowsrv_ConnectServer
  11. }
  12. var (
  13. instance *flowManager
  14. once sync.Once
  15. )
  16. func GetFlowMgrInstance() *flowManager {
  17. once.Do(func() {
  18. instance = &flowManager{
  19. flowMap: make(map[string]pb.Flowsrv_ConnectServer),
  20. }
  21. })
  22. return instance
  23. }
  24. func (manager *flowManager) SetFlow(uid string, flow pb.Flowsrv_ConnectServer) {
  25. manager.flowMap[uid] = flow
  26. }
  27. func (manager *flowManager) GetFlow(uid string) pb.Flowsrv_ConnectServer {
  28. return manager.flowMap[uid]
  29. }