55 lines
970 B
Go
55 lines
970 B
Go
package uniss
|
|
|
|
import (
|
|
"context"
|
|
"dashboard/logger"
|
|
"dashboard/models"
|
|
"dashboard/pkg/rpcsup"
|
|
"dashboard/settings"
|
|
"fmt"
|
|
)
|
|
|
|
type UnisRpcService struct {
|
|
*logger.Logger
|
|
}
|
|
|
|
func NewRpcService(log *logger.Logger) *UnisRpcService {
|
|
res := new(UnisRpcService)
|
|
|
|
res.Logger = log
|
|
|
|
return res
|
|
}
|
|
|
|
func (u *UnisRpcService) Config(res models.UnisRpcRequest, rsp *models.UnisRpcResponse) error {
|
|
u.Sugar().Info("rpc server get mesage", res)
|
|
|
|
rsp.Id = res.Id
|
|
|
|
return nil
|
|
}
|
|
|
|
type unisRpcServer struct {
|
|
log *logger.Logger
|
|
port int
|
|
host string
|
|
typec string
|
|
}
|
|
|
|
func newUnisRpcServer(log *logger.Logger, conf *settings.RpcConfig) *unisRpcServer {
|
|
res := new(unisRpcServer)
|
|
res.log = log
|
|
|
|
res.port = conf.Port
|
|
res.host = conf.Host
|
|
res.typec = conf.Type
|
|
|
|
return res
|
|
}
|
|
|
|
func (u *unisRpcServer) rpcListenAndServe(ctx context.Context) error {
|
|
addrees := fmt.Sprintf("%s:%d", u.host, u.port)
|
|
|
|
return rpcsup.JsonServer(ctx, u.log, addrees, NewRpcService(u.log))
|
|
}
|