当前位置: 首页>>代码示例>>Golang>>正文


Golang AgentServiceRegistration.Check方法代码示例

本文整理汇总了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)
}
开发者ID:m3adow,项目名称:registrator_consul_kv,代码行数:34,代码来源:consul.go

示例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)
}
开发者ID:jojimt,项目名称:netplugin,代码行数:11,代码来源:consul.go

示例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)
}
开发者ID:Dexels,项目名称:registrator,代码行数:20,代码来源:consul.go

示例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,
				}))
开发者ID:cloudfoundry,项目名称:locket,代码行数:31,代码来源:registration_runner_test.go


注:本文中的github.com/hashicorp/consul/api.AgentServiceRegistration.Check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。