mirror of
https://github.com/dragonheim/gagent.git
synced 2025-01-18 04:56:28 -08:00
Removing consul service as it is not ready for inclusion yet.
This commit is contained in:
parent
89f1dce976
commit
c677d30cf5
1 changed files with 0 additions and 61 deletions
|
@ -1,61 +0,0 @@
|
|||
package consulservice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
consul "github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
||||
//Client provides an interface for getting data out of Consul
|
||||
type Client interface {
|
||||
// Get a Service from consul
|
||||
Service(string, string) ([]string, error)
|
||||
// Register a service with local agent
|
||||
Register(string, int) error
|
||||
// Deregister a service with local agent
|
||||
DeRegister(string) error
|
||||
}
|
||||
|
||||
type client struct {
|
||||
consul *consul.Client
|
||||
}
|
||||
|
||||
//NewConsul returns a Client interface for given consul address
|
||||
func NewConsulClient(addr string) (Client, error) {
|
||||
config := consul.DefaultConfig()
|
||||
config.Address = addr
|
||||
c, err := consul.NewClient(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &client{c}, nil
|
||||
//return &client{consul: c}, nil
|
||||
}
|
||||
|
||||
// Register a service with consul local agent
|
||||
func (c *client) Register(name string, port int) error {
|
||||
reg := &consul.AgentServiceRegistration{
|
||||
ID: name,
|
||||
Name: name,
|
||||
Port: port,
|
||||
}
|
||||
return c.consul.Agent().ServiceRegister(reg)
|
||||
}
|
||||
|
||||
// DeRegister a service with consul local agent
|
||||
func (c *client) DeRegister(id string) error {
|
||||
return c.consul.Agent().ServiceDeregister(id)
|
||||
}
|
||||
|
||||
// Service return a service
|
||||
func (c *client) Service(service, tag string) ([]*consul.ServiceEntry, *consul.QueryMeta, error) {
|
||||
passingOnly := true
|
||||
addrs, meta, err := c.consul.Health().Service(service, tag, passingOnly, nil)
|
||||
if len(addrs) == 0 && err == nil {
|
||||
return nil, nil, fmt.Errorf("service ( %s ) was not found", service)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return addrs, meta, nil
|
||||
}
|
Loading…
Add table
Reference in a new issue