func (r *ConsulAdapter) Register(service *bridge.Service) error { agentService := new(consulapi.AgentService) agentService.ID = service.ID agentService.Service = service.Name agentService.Port = service.Port agentService.Tags = service.Tags agentService.Address = service.IP registration := new(consulapi.CatalogRegistration) registration.Node = Hostname registration.Address = service.Origin.HostIP registration.Datacenter = service.Attrs["region"] registration.Service = agentService registration.Check = nil writeOptions := new(consulapi.WriteOptions) writeOptions.Datacenter = service.Attrs["region"] out, _ := json.Marshal(registration) log.Println("REGISTERING :", string(out)) _, res := r.client.Catalog().Register(registration, writeOptions) return res }
func (m *Meta) WriteOptions() *consulapi.WriteOptions { writeOpts := new(consulapi.WriteOptions) if m.token != "" { writeOpts.Token = m.token } if m.dc != "" { writeOpts.Datacenter = m.dc } return writeOpts }
func (c *Cmd) WriteOptions() *consulapi.WriteOptions { csl := c.consul writeOpts := new(consulapi.WriteOptions) if csl.token != "" { writeOpts.Token = csl.token } if csl.dc != "" { writeOpts.Datacenter = csl.dc } return writeOpts }
func (m *Meta) WriteOptions() *consulapi.WriteOptions { writeOpts := new(consulapi.WriteOptions) if os.Getenv("CONSUL_TOKEN") != "" { writeOpts.Token = os.Getenv("CONSUL_TOKEN") } if m.token != "" { writeOpts.Token = m.token } if m.dc != "" { writeOpts.Datacenter = m.dc } return writeOpts }
func (r *ConsulAdapter) Deregister(service *bridge.Service) error { deRegistration := new(consulapi.CatalogDeregistration) deRegistration.Node = Hostname deRegistration.Address = "" deRegistration.Datacenter = service.Attrs["region"] deRegistration.ServiceID = service.ID deRegistration.CheckID = "" writeOptions := new(consulapi.WriteOptions) writeOptions.Datacenter = service.Attrs["region"] out, _ := json.Marshal(deRegistration) log.Println("DE-REGISTERING :", string(out)) _, res := r.client.Catalog().Deregister(deRegistration, writeOptions) return res }