Simplify indexer.AddService implementation

This commit is contained in:
ionutboangiu
2024-12-04 17:43:31 +02:00
committed by Dan Christian Bogos
parent 82c985cdbe
commit fbc9afc784
2 changed files with 4 additions and 4 deletions

View File

@@ -41,10 +41,10 @@ func (sI *ServiceIndexer) GetService(srvID string) Service {
return sI.srvS[srvID]
}
// AddService adds a service based on it's id to the index
func (sI *ServiceIndexer) AddService(srvID string, srv Service) {
// AddService registers a service in the indexer using its name as key
func (sI *ServiceIndexer) AddService(s Service) {
sI.mux.Lock()
sI.srvS[srvID] = srv
sI.srvS[s.ServiceName()] = s
sI.mux.Unlock()
}

View File

@@ -76,7 +76,7 @@ func (srvMngr *ServiceManager) StartServices(ctx *context.Context, shtDwn contex
func (srvMngr *ServiceManager) AddServices(services ...Service) {
srvMngr.Lock()
for _, srv := range services {
srvMngr.serviceIndexer.AddService(srv.ServiceName(), srv)
srvMngr.serviceIndexer.AddService(srv)
if sAPIData, hasAPIData := serviceAPIData[srv.ServiceName()]; hasAPIData { // Add the internal connections
rpcIntChan := make(chan birpc.ClientConnector, 1)
srvMngr.connMgr.AddInternalConn(sAPIData[1], sAPIData[0], rpcIntChan)