itltf512116 7a6df3abd3
Tuoyun 新增单容器单进程的部署方式 (#103)
* feat 新增deploy:单容器单进程模型部署

* feat 新增openim内部各组件的host名称配置;
fix 独立容器部署镜像文档;

* feat 新增注释说明
2021-12-17 10:49:01 +08:00

65 lines
1.5 KiB
Go

package auth
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbAuth "Open_IM/pkg/proto/auth"
"net"
"strconv"
"strings"
"github.com/spf13/viper"
"google.golang.org/grpc"
)
type rpcAuth struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewRpcAuthServer(port int) *rpcAuth {
log.NewPrivateLog("auth")
return &rpcAuth{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (rpc *rpcAuth) Run() {
log.Info("", "", "rpc get_token init...")
address := ":" + strconv.Itoa(rpc.rpcPort)
listener, err := net.Listen("tcp", address)
if err != nil {
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
return
}
log.Info("", "", "listen network success, address = %s", address)
//grpc server
srv := grpc.NewServer()
defer srv.GracefulStop()
//service registers with etcd
pbAuth.RegisterAuthServer(srv, rpc)
host := viper.GetString("endpoints.rpc_auth")
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), host, rpc.rpcPort, rpc.rpcRegisterName, 10)
if err != nil {
log.Error("", "", "register rpc get_token to etcd failed, err = %s", err.Error())
return
}
err = srv.Serve(listener)
if err != nil {
log.Info("", "", "rpc get_token fail, err = %s", err.Error())
return
}
log.Info("", "", "rpc get_token init success")
}