dashboard/services/uniss/communicate.go

55 lines
1.4 KiB
Go

package uniss
import (
"context"
"dashboard/pkg/errgroups"
"dashboard/pkg/rpcsup"
"dashboard/settings"
"fmt"
)
type communicateService struct {
rpcClientStub *rpcClientStub
rpcService *rpcsup.RpcService
httpServerHandler *httpServerHandler
httpClientHandler *httpClientHandler
}
func newcommunicateService(conf *settings.UnisConfig) (res *communicateService, err error) {
res = new(communicateService)
var rpcConf = &rpcsup.RpcConfig{
Typec: conf.RpcConfig.Type,
Network: conf.RpcConfig.Network,
Address: fmt.Sprintf("%s:%d", conf.RpcConfig.Host, conf.RpcConfig.BasePort+conf.Instances)}
res.rpcService, err = rpcsup.NewRpcService(rpcConf)
if err != nil {
log.Sugar().Errorf("New rpc service error: %v", err)
return
}
log.Sugar().Infof("New rpc service ok type: %s, network: %s, address: %s", rpcConf.Typec, rpcConf.Network, rpcConf.Address)
err = res.rpcService.Register(newrpcServerStub())
if err != nil {
log.Sugar().Errorf("Rpc service register error: %v", err)
return
}
log.Sugar().Infof("Rpc service register all ok")
res.httpServerHandler = newhttpServerHandler()
res.rpcClientStub = newRpcClients(conf.RpcConfig)
res.httpClientHandler = newhttpClientHandle(conf.HttpClientConfig.Clients)
return
}
func (c *communicateService) Run(ctx context.Context) error {
ewgs := errgroups.NewErrGroup()
ewgs.Add(c.rpcService)
ewgs.Add(c.httpClientHandler.swarm)
return ewgs.Run(ctx)
}