• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang api.AgentServiceRegistration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/hashicorp/consul/api.AgentServiceRegistration的典型用法代码示例。如果您正苦于以下问题:Golang AgentServiceRegistration类的具体用法?Golang AgentServiceRegistration怎么用?Golang AgentServiceRegistration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AgentServiceRegistration类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: resourceConsulServiceCreate

func resourceConsulServiceCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*consulapi.Client)
	agent := client.Agent()

	name := d.Get("name").(string)
	identifier := name

	if serviceId, ok := d.GetOk("service_id"); ok {
		identifier = serviceId.(string)
	}

	registration := consulapi.AgentServiceRegistration{Name: name, ID: identifier}

	if address, ok := d.GetOk("address"); ok {
		registration.Address = address.(string)
	}

	if port, ok := d.GetOk("port"); ok {
		registration.Port = port.(int)
	}

	if v, ok := d.GetOk("tags"); ok {
		vs := v.([]interface{})
		s := make([]string, len(vs))
		for i, raw := range vs {
			s[i] = raw.(string)
		}
		registration.Tags = s
	}

	if err := agent.ServiceRegister(&registration); err != nil {
		return fmt.Errorf("Failed to register service '%s' with Consul agent: %v", name, err)
	}

	// Update the resource
	if serviceMap, err := agent.Services(); err != nil {
		return fmt.Errorf("Failed to read services from Consul agent: %v", err)
	} else if service, ok := serviceMap[identifier]; !ok {
		return fmt.Errorf("Failed to read service '%s' from Consul agent: %v", identifier, err)
	} else {
		d.SetId(service.ID)

		d.Set("address", service.Address)
		d.Set("service_id", service.ID)
		d.Set("name", service.Service)
		d.Set("port", service.Port)
		tags := make([]string, 0, len(service.Tags))
		for _, tag := range service.Tags {
			tags = append(tags, tag)
		}
		d.Set("tags", tags)
	}

	return nil
}
开发者ID:paultyng,项目名称:terraform,代码行数:55,代码来源:resource_consul_service.go


示例2: register

func register() {
	registration := new(consulApi.AgentServiceRegistration)
	registration.ID = serviceId
	registration.Name = serviceName
	registration.Port, _ = strconv.Atoi(servicePort)
	registration.Tags = serviceTags
	registration.Address = serviceIp
	// TODO build Check latter
	log.Println("ID is: ", registration.ID)
	log.Println("Name is: ", registration.Name)
	log.Println("Port is: ", registration.Port)
	log.Println("Tags is: ", registration.Tags)
	log.Println("Address is: ", registration.Address)
	consulClient.Agent().ServiceRegister(registration)
}
开发者ID:zufangzi,项目名称:chaos,代码行数:15,代码来源:registrator.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()
		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


示例4: doConsulAddService

func doConsulAddService(agent *consulapi.Agent, ConsulName string, address string) (*consulapi.AgentService, error) {
	registration := new(consulapi.AgentServiceRegistration)
	registration.Name = ConsulName
	registration.Port = 80
	registration.Address = address
	err := agent.ServiceRegister(registration)
	if err != nil {
		return nil, err
	}
	svcs, err := agent.Services()
	if err != nil {
		return nil, err
	}
	svc, found := svcs[registration.Name]
	if !found {
		return nil, errors.New("Could not find service " + registration.Name + " after registration!")
	}
	return svc, nil
}
开发者ID:kainz,项目名称:registrator,代码行数:19,代码来源:hipache.go


示例5: createService

// createService creates a Consul AgentService from a Nomad ConsulService.
func (c *Syncer) createService(service *structs.Service, domain ServiceDomain, key ServiceKey) (*consul.AgentServiceRegistration, error) {
	c.registryLock.RLock()
	defer c.registryLock.RUnlock()

	srv := consul.AgentServiceRegistration{
		ID:   string(generateConsulServiceID(domain, key)),
		Name: service.Name,
		Tags: service.Tags,
	}
	host, port := c.addrFinder(service.PortLabel)
	if host != "" {
		srv.Address = host
	}

	if port != 0 {
		srv.Port = port
	}

	return &srv, nil
}
开发者ID:hooklift,项目名称:nomad,代码行数:21,代码来源:syncer.go


示例6: 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.Checks = r.buildChecks(service)
	return r.client.Agent().ServiceRegister(registration)
}
开发者ID:Marmelatze,项目名称:registrator,代码行数:10,代码来源:consul.go


示例7: SetService

func SetService(c *cli.Context) {
	// Get client
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	reg := new(api.AgentServiceRegistration)

	for _, arg := range append(c.Args().Tail(), c.Args().First()) {
		split := strings.SplitN(arg, "=", 2)
		switch strings.ToLower(split[0]) {
		case "address":
			reg.Address = split[1]
		case "name":
			reg.Name = split[1]
		case "id":
			reg.ID = split[1]
		case "port":
			port, _ := strconv.ParseInt(split[1], 10, 32)
			reg.Port = int(port)
		case "tags":
			tags := strings.Split(split[1], ",")
			reg.Tags = tags
		}
	}

	err = cfg.client.Agent().ServiceRegister(reg)
	if err != nil {
		log.Errorf("%v\n", err)
		return
	}
	log.Println("Success")
}
开发者ID:colebrumley,项目名称:consulctl,代码行数:35,代码来源:services.go


示例8: updateConsulTags

// the types are so close yet SO DIFFERENT
func updateConsulTags(agent *consulapi.Agent, svc *consulapi.AgentService) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.Name = svc.Service
	registration.ID = svc.ID
	registration.Tags = svc.Tags
	registration.Port = svc.Port
	registration.Address = svc.Address
	return agent.ServiceRegister(registration)
}
开发者ID:kainz,项目名称:registrator,代码行数:10,代码来源:hipache.go


示例9: 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


示例10: Register

func (r *Adapter) Register(group *types.ServiceGroup) error {
	for _, service := range group.Services {
		if r.dryRun {
			log.WithFields(log.Fields{
				"prefix": "consul",
				"ip":     group.IP,
				"id":     service.ID,
				"name":   service.Name,
				"port":   service.ExposedPort,
			}).Info("[dry-run] Would register service")
			continue
		}

		log.WithFields(log.Fields{
			"prefix": "consul",
			"ip":     group.IP,
			"id":     service.ID,
			"name":   service.Name,
			"port":   service.ExposedPort,
		}).Info("Registering service")

		registration := new(consulAPI.AgentServiceRegistration)
		registration.Address = group.IP
		registration.ID = service.ID
		registration.Name = service.Name
		registration.Tags = service.Tags
		registration.Port = service.ExposedPort

		err := r.client.Agent().ServiceRegister(registration)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:x-cray,项目名称:marathon-registrator,代码行数:36,代码来源:consul_adapter.go


示例11:

	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Service Registration Integration", func() {
	const (
		serviceID   = "test-id"
		serviceName = "Test-Service"
	)

	var (
		consulClient consuladapter.Client
		logger       lager.Logger
		clock        *fakeclock.FakeClock

		registration        *api.AgentServiceRegistration
		registrationProcess ifrit.Process
	)

	BeforeEach(func() {
		consulClient = consulRunner.NewClient()

		logger = lagertest.NewTestLogger("test")
		clock = fakeclock.NewFakeClock(time.Now())
		registration = &api.AgentServiceRegistration{
			ID:      serviceID,
			Name:    serviceName,
			Tags:    []string{"a", "b", "c"},
			Port:    8080,
			Address: "127.0.0.1",
开发者ID:cloudfoundry,项目名称:locket,代码行数:32,代码来源:registration_runner_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang api.Client类代码示例发布时间:2022-05-23
下一篇:
Golang api.AgentServiceCheck类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap