flowmgr.go 726 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. }
  30. func (manager *flowManager) RemoveFlow(uid string) {
  31. delete(manager.flowMap, uid)
  32. }