From ef0e93169a9212889bef6d858c9ae9e2c47a4a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E6=B5=B7=E4=BB=B2=E5=AD=90?= Date: Sat, 23 Jan 2021 11:16:46 +0800 Subject: [PATCH] =?UTF-8?q?consul=E9=80=9A=E7=94=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=9E=84=E6=80=9D=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consul/consul-service.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/consul/consul-service.go b/consul/consul-service.go index 0d6ba62..08ecec6 100644 --- a/consul/consul-service.go +++ b/consul/consul-service.go @@ -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"