本文整理汇总了Golang中github.com/hashicorp/consul/api.AgentServiceRegistration.Check方法的典型用法代码示例。如果您正苦于以下问题:Golang AgentServiceRegistration.Check方法的具体用法?Golang AgentServiceRegistration.Check怎么用?Golang AgentServiceRegistration.Check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hashicorp/consul/api.AgentServiceRegistration
的用法示例。
在下文中一共展示了AgentServiceRegistration.Check方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Register
func (r *ConsulAdapter) Register(service *bridge.Service) error {
registration := new(consulapi.AgentServiceRegistration)
registration.ID = service.ID
registration.Name = service.Name
registration.Port = service.Port
registration.Tags = service.Tags
registration.Address = service.IP
registration.Check = r.buildCheck(service)
if r.servicePrefix != "" {
kv := r.client.KV()
addr := service.IP + ":" + strconv.Itoa(service.Port)
host_path := r.servicePrefix + "/" + "nodes/" + service.ID + "/"
service_path := r.servicePrefix + "/" + "services/" + service.Name + "/" + service.ID + "/"
_, err := kv.Put(&consulapi.KVPair{Key: host_path + "URI", Value: []byte(addr)}, nil)
if err != nil {
return (err)
}
_, err = kv.Put(&consulapi.KVPair{Key: service_path + "URI", Value: []byte(addr)}, nil)
if err != nil {
return (err)
}
for k, v := range service.Attrs {
_, err := kv.Put(&consulapi.KVPair{Key: host_path + k, Value: []byte(v)}, nil)
if err != nil {
return (err)
}
_, err = kv.Put(&consulapi.KVPair{Key: service_path + k, Value: []byte(v)}, nil)
if err != nil {
return (err)
}
}
}
return r.client.Agent().ServiceRegister(registration)
}
示例2: Register
// Register will register ConsulAdapter's interface with RegistryAdapter
func (r *ConsulAdapter) Register(service *bridge.Service) error {
registration := new(consulapi.AgentServiceRegistration)
registration.ID = service.ID
registration.Name = service.Name
registration.Port = service.Port
registration.Tags = service.Tags
registration.Address = service.IP
registration.Check = r.buildCheck(service)
return r.client.Agent().ServiceRegister(registration)
}
示例3: Register
func (r *ConsulAdapter) Register(service *bridge.Service) error {
registration := new(consulapi.AgentServiceRegistration)
registration.ID = service.ID
registration.Name = service.Name
registration.Port = service.Port
registration.Tags = service.Tags
registration.Address = service.IP
registration.Check = r.buildCheck(service)
if r.servicePrefix != "" {
kv := r.client.KV()
for k, v := range service.Attrs {
pair := &consulapi.KVPair{Key: r.servicePrefix + "/" + service.ID + "/" + k, Value: []byte(v)}
_, err := kv.Put(pair, nil)
if err != nil {
panic(err)
}
}
}
return r.client.Agent().ServiceRegister(registration)
}
示例4:
Expect(err).NotTo(HaveOccurred())
service, ok := services[registration.ID]
Expect(ok).To(BeTrue())
Expect(*service).To(Equal(api.AgentService{
ID: registration.ID,
Service: registration.Name,
Tags: registration.Tags,
Port: registration.Port,
Address: registration.Address,
}))
})
Context("when using a TTL check", func() {
BeforeEach(func() {
registration.Check = &api.AgentServiceCheck{
TTL: "10s",
}
})
It("registers the service", func() {
services, err := consulClient.Agent().Services()
Expect(err).NotTo(HaveOccurred())
service, ok := services[registration.ID]
Expect(ok).To(BeTrue())
Expect(*service).To(Equal(api.AgentService{
ID: registration.ID,
Service: registration.Name,
Tags: registration.Tags,
Port: registration.Port,
Address: registration.Address,
}))