acceptor.go 556 B

123456789101112131415161718192021222324252627
  1. package peer
  2. import "go.uber.org/zap"
  3. type Acceptor interface {
  4. Start(string, *SessionManager, *zap.Logger) error
  5. Stop(*SessionManager)
  6. }
  7. var acceptorList = make(map[string]Acceptor)
  8. func RegisterAcceptor(name string, server Acceptor) {
  9. if server == nil {
  10. panic("acceptor: Register provide is nil")
  11. }
  12. if _, dup := acceptorList[name]; dup {
  13. panic("acceptor: Register called twice for provide " + name)
  14. }
  15. acceptorList[name] = server
  16. }
  17. func GetAcceptor(name string) Acceptor {
  18. if v, ok := acceptorList[name]; ok {
  19. return v
  20. }
  21. return nil
  22. }