Consul refactor
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"git.pbiernat.dev/egommerce/go-api-pkg/config"
|
||||
consul "github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/connect"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
@@ -18,6 +19,7 @@ type Service struct {
|
||||
pathPrefix string
|
||||
port int
|
||||
ttl time.Duration
|
||||
client *consul.Client
|
||||
agent *consul.Agent
|
||||
connect *consul.Connect
|
||||
kv *consul.KV
|
||||
@@ -39,8 +41,9 @@ func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.client = client
|
||||
s.agent = client.Agent()
|
||||
s.connect = client.Connect()
|
||||
s.kv = client.KV()
|
||||
|
||||
return s, nil
|
||||
@@ -103,8 +106,8 @@ func (s *Service) Unregister() error {
|
||||
return s.agent.ServiceDeregister(s.GetID())
|
||||
}
|
||||
|
||||
func (s *Service) Connect() *consul.Connect {
|
||||
return s.connect
|
||||
func (s *Service) Connect() (*connect.Service, error) {
|
||||
return connect.NewService(s.Name, s.client)
|
||||
}
|
||||
|
||||
func (s *Service) KV() *consul.KV {
|
||||
|
||||
Reference in New Issue
Block a user