consul通用组件构思中
This commit is contained in:
parent
c92e62ab16
commit
ef0e93169a
|
|
@ -8,28 +8,29 @@ import (
|
|||
)
|
||||
|
||||
//Register 注册服务到consul
|
||||
func Register() {
|
||||
func Register(id string, name string, port int, tags ...string) {
|
||||
// 创建连接consul服务配置
|
||||
config := consulapi.DefaultConfig()
|
||||
config.Address = "127.0.0.1:8500"
|
||||
client, err := consulapi.NewClient(config)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"func": "NewClient",
|
||||
"func": "consulapi.NewClient",
|
||||
}).Errorf("%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 创建注册到consul的服务到
|
||||
registration := new(consulapi.AgentServiceRegistration)
|
||||
registration.ID = "111"
|
||||
registration.Name = "go-consul-test"
|
||||
registration.Port = 8081
|
||||
registration.Tags = []string{"go-consul-test"}
|
||||
registration.Address = "10.13.153.128"
|
||||
registration.ID = id
|
||||
registration.Name = name
|
||||
registration.Port = port
|
||||
registration.Tags = tags
|
||||
registration.Address = "0.0.0.0"
|
||||
|
||||
// 增加consul健康检查回调函数
|
||||
check := new(consulapi.AgentServiceCheck)
|
||||
|
||||
check.HTTP = fmt.Sprintf("http://%s:%d", registration.Address, registration.Port)
|
||||
check.Timeout = "5s"
|
||||
check.Interval = "5s"
|
||||
|
|
|
|||
Loading…
Reference in New Issue