Consul refactor

This commit is contained in:
PB
2023-06-29 14:25:08 +02:00
parent 5451899e48
commit 2375c2a23a
3 changed files with 817 additions and 56 deletions

View File

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