59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package uniss
|
|
|
|
import (
|
|
"context"
|
|
"dashboard/logger"
|
|
"dashboard/models"
|
|
"dashboard/pkg/errgroups"
|
|
"dashboard/settings"
|
|
)
|
|
|
|
type UnisStation struct {
|
|
log *logger.Logger
|
|
conf *settings.UnisConfig
|
|
httpHandle *httpHandle
|
|
commonService *commonService
|
|
}
|
|
|
|
func NewUnis(log *logger.Logger, conf *settings.UnisConfig) *UnisStation {
|
|
res := new(UnisStation)
|
|
|
|
res.log = log
|
|
res.conf = conf
|
|
|
|
res.httpHandle = newhttpHandle()
|
|
res.commonService = newcommonService(res.httpHandle)
|
|
res.commonService.rpcClients = newRpcClients(log, conf.RpcConfig.Port)
|
|
|
|
return res
|
|
}
|
|
|
|
func (u *UnisStation) GetHttpChannel() chan *models.UnisHttpRequest {
|
|
return u.httpHandle.httpC
|
|
}
|
|
|
|
func (u *UnisStation) mesageHandle(ctx context.Context) error {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
u.log.Error("Unis mesageHandle cancel by ctx")
|
|
return ctx.Err()
|
|
case httpMsg := <-u.httpHandle.httpC:
|
|
u.httpHandle.httpHandle(httpMsg)
|
|
// default:
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func (u *UnisStation) Run(ctx context.Context) error {
|
|
rpc := newUnisRpcServer(u.log, u.conf.RpcConfig)
|
|
|
|
ewgs := errgroups.NewErrGroupFunc()
|
|
|
|
ewgs.Add(rpc.rpcListenAndServe)
|
|
ewgs.Add(u.mesageHandle)
|
|
|
|
return ewgs.Run(ctx)
|
|
}
|