Removing consul service as it is not ready for inclusion yet.

This commit is contained in:
James Wells 2022-08-05 06:44:11 -07:00
parent 89f1dce976
commit c677d30cf5
Signed by: jwells
GPG key ID: 73196D10B8E65666

View file

@ -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
}