提交 f648db8d 编写于 作者: styl3's avatar styl3 提交者: Gao Hongtao

fixed instance register without hostname and pid (#35)

* fixed instance register without hostname and pid

* format code using gofmt -s
上级 1eaab803
......@@ -19,6 +19,7 @@ import (
"errors"
"log"
"os"
"strconv"
"time"
"github.com/golang/protobuf/proto"
......@@ -140,12 +141,31 @@ func (r *gRPCReporter) registerService(name string) error {
}
func (r *gRPCReporter) registerInstance(name string) error {
var props []*common.KeyStringValuePair
if os.Getpid() > 0 {
kv := &common.KeyStringValuePair{
Key: "process_no",
Value: strconv.Itoa(os.Getpid()),
}
props = append(props, kv)
}
if hs, err := os.Hostname(); err == nil {
if hs != "" {
kv := &common.KeyStringValuePair{
Key: "host_name",
Value: hs,
}
props = append(props, kv)
}
}
in := &register.ServiceInstances{
Instances: []*register.ServiceInstance{
{
ServiceId: r.serviceID,
InstanceUUID: name,
Time: tool.Millisecond(time.Now()),
Properties: props,
},
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册