Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1de38fdfdf | |||
| 4d1f3644b0 | |||
| 71b3f13284 | |||
| c64bc3fe6b | |||
| 016bddb5c4 | |||
| 98d85810f3 | |||
| 3fc1191f6e | |||
| 52793ac244 | |||
| f8a1ae841d | |||
| 9d424742d6 |
@@ -9,6 +9,7 @@ import (
|
||||
"git.pbiernat.dev/egommerce/go-api-pkg/config"
|
||||
consul "github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/connect"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
@@ -61,25 +62,23 @@ func (s *Service) GetID() string {
|
||||
}
|
||||
|
||||
func (s *Service) GetFullAddr() string {
|
||||
return fmt.Sprintf("http://%s:%d/", s.domain, s.port)
|
||||
return fmt.Sprintf("https://%s:%d/", s.domain, s.port)
|
||||
}
|
||||
|
||||
func (s *Service) Register() error {
|
||||
def := &consul.AgentServiceRegistration{
|
||||
ID: s.GetID(),
|
||||
Kind: consul.ServiceKindConnectProxy,
|
||||
ID: s.GetID(),
|
||||
// Kind: consul.ServiceKindConnectProxy,
|
||||
Name: s.Name,
|
||||
Address: s.Address,
|
||||
Port: s.port,
|
||||
Tags: s.getTags(),
|
||||
Connect: &consul.AgentServiceConnect{
|
||||
SidecarService: &consul.AgentServiceRegistration{
|
||||
// Port: s.port,
|
||||
},
|
||||
},
|
||||
Proxy: &consul.AgentServiceConnectProxyConfig{
|
||||
DestinationServiceName: s.Name,
|
||||
Native: true,
|
||||
},
|
||||
// Proxy: &consul.AgentServiceConnectProxyConfig{
|
||||
// DestinationServiceName: s.Name,
|
||||
// },
|
||||
Check: &consul.AgentServiceCheck{
|
||||
TTL: s.ttl.String(),
|
||||
Status: "passing",
|
||||
@@ -91,16 +90,23 @@ func (s *Service) Register() error {
|
||||
return err
|
||||
}
|
||||
|
||||
go func(s *Service) { // startup register
|
||||
return nil
|
||||
}
|
||||
func (s *Service) Unregister() error {
|
||||
return s.agent.ServiceDeregister(s.GetID())
|
||||
}
|
||||
|
||||
func (s *Service) InitHealthChecks() {
|
||||
go func() { // startup register
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
for range ticker.C {
|
||||
if ok, _ := s.healthCheck(); ok {
|
||||
ticker.Stop()
|
||||
}
|
||||
}
|
||||
}(s)
|
||||
}()
|
||||
|
||||
go func(s *Service) { // TTL
|
||||
go func() { // TTL
|
||||
interval := s.ttl - time.Second*2 // 2 seconds overhead
|
||||
ticker := time.NewTicker(interval)
|
||||
for range ticker.C {
|
||||
@@ -108,21 +114,18 @@ func (s *Service) Register() error {
|
||||
fmt.Printf("TTL Error #: %v\n", err)
|
||||
}
|
||||
}
|
||||
}(s)
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *Service) Unregister() error {
|
||||
return s.agent.ServiceDeregister(s.GetID())
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *Service) Connect() (*connect.Service, error) {
|
||||
// srvName := s.Name
|
||||
srvName := s.Name
|
||||
svc, err := connect.NewService(srvName, s.client)
|
||||
l := hclog.New(&hclog.LoggerOptions{
|
||||
Name: "consul-registry",
|
||||
Level: hclog.Trace,
|
||||
})
|
||||
svc, err := connect.NewServiceWithLogger(s.Name, s.client, l)
|
||||
s.connect = svc
|
||||
cnf := svc.ServerTLSConfig()
|
||||
fmt.Printf("CONNECT SERVER:: %s CONFIG:: %v\n", srvName, cnf)
|
||||
fmt.Printf("CONNECT SERVER:: %s CONFIG:: %v\n", s.Name, cnf)
|
||||
for k, c := range cnf.Certificates {
|
||||
fmt.Printf("CONNECT CERT %d: %v", k, c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user