对动态ip port进行获取
This commit is contained in:
parent
9af8b46812
commit
b048a2e1f2
14
grpc/grpc.go
14
grpc/grpc.go
|
|
@ -38,6 +38,14 @@ func Init(config *Config) *grpc.Server {
|
|||
return rpc
|
||||
}
|
||||
|
||||
func IPAddress() string {
|
||||
return conf.Address
|
||||
}
|
||||
|
||||
func Port() int {
|
||||
return conf.Port
|
||||
}
|
||||
|
||||
func Start() {
|
||||
//注册反射 用于grpcurl调试
|
||||
reflection.Register(rpc)
|
||||
|
|
@ -48,6 +56,12 @@ func Start() {
|
|||
if err != nil {
|
||||
log.Fatal("net.ResolveTCPAddr", err)
|
||||
}
|
||||
if addr.IP.String() != conf.Address {
|
||||
conf.Address = addr.IP.String()
|
||||
}
|
||||
if addr.Port != conf.Port {
|
||||
conf.Port = addr.Port
|
||||
}
|
||||
log.Printf("starting grpc service on %s:%d", addr.IP, addr.Port)
|
||||
lis, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue