github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/common/transport/engine_manager.go (about) 1 package transport 2 3 import "github.com/nyan233/littlerpc/core/container" 4 5 var ( 6 Manager = &manager{} 7 ) 8 9 type manager struct { 10 serverEngineCollection container.SyncMap118[string, NewServerBuilder] 11 clientEngineCollection container.SyncMap118[string, NewClientBuilder] 12 } 13 14 func (m *manager) RegisterServerEngine(scheme string, builder NewServerBuilder) { 15 m.serverEngineCollection.Store(scheme, builder) 16 } 17 18 func (m *manager) GetServerEngine(scheme string) NewServerBuilder { 19 builder, _ := m.serverEngineCollection.LoadOk(scheme) 20 return builder 21 } 22 23 func (m *manager) RegisterClientEngine(scheme string, builder NewClientBuilder) { 24 m.clientEngineCollection.Store(scheme, builder) 25 } 26 27 func (m *manager) GetClientEngine(scheme string) NewClientBuilder { 28 builder, _ := m.clientEngineCollection.LoadOk(scheme) 29 return builder 30 } 31 32 func init() { 33 Manager.RegisterServerEngine("nbio_tcp", NewNBioTcpServer) 34 Manager.RegisterClientEngine("nbio_tcp", NewNBioTcpClient) 35 Manager.RegisterServerEngine("nbio_ws", NewNBioWebsocketServer) 36 Manager.RegisterClientEngine("nbio_ws", NewNBioWebsocketClient) 37 Manager.RegisterServerEngine("std_tcp", NewStdTcpServer) 38 Manager.RegisterClientEngine("std_tcp", NewStdTcpClient) 39 }