|
|
|
|
@@ -61,18 +61,29 @@ func (s *Service) GetID() string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Service) GetFullAddr() string {
|
|
|
|
|
return fmt.Sprintf("http://%s:%d/", s.Address, s.port)
|
|
|
|
|
return fmt.Sprintf("https://%s:%d/", s.domain, s.port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Service) Register() error {
|
|
|
|
|
def := &consul.AgentServiceRegistration{
|
|
|
|
|
ID: s.GetID(),
|
|
|
|
|
ID: s.GetID(),
|
|
|
|
|
// Kind: consul.ServiceKindConnectProxy,
|
|
|
|
|
Name: s.Name,
|
|
|
|
|
Address: s.Address,
|
|
|
|
|
Port: s.port,
|
|
|
|
|
Tags: s.getTags(),
|
|
|
|
|
Connect: &consul.AgentServiceConnect{
|
|
|
|
|
Native: true,
|
|
|
|
|
// SidecarService: &consul.AgentServiceRegistration{
|
|
|
|
|
// Port: s.port,
|
|
|
|
|
// },
|
|
|
|
|
},
|
|
|
|
|
// Proxy: &consul.AgentServiceConnectProxyConfig{
|
|
|
|
|
// DestinationServiceName: s.Name,
|
|
|
|
|
// },
|
|
|
|
|
Check: &consul.AgentServiceCheck{
|
|
|
|
|
TTL: s.ttl.String(),
|
|
|
|
|
Status: "passing",
|
|
|
|
|
DeregisterCriticalServiceAfter: "10s",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
@@ -107,8 +118,15 @@ func (s *Service) Unregister() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Service) Connect() (*connect.Service, error) {
|
|
|
|
|
svc, err := connect.NewService(s.Name, s.client)
|
|
|
|
|
// srvName := s.Name
|
|
|
|
|
srvName := s.Name
|
|
|
|
|
svc, err := connect.NewService(srvName, s.client)
|
|
|
|
|
s.connect = svc
|
|
|
|
|
cnf := svc.ServerTLSConfig()
|
|
|
|
|
fmt.Printf("CONNECT SERVER:: %s CONFIG:: %v\n", srvName, cnf)
|
|
|
|
|
for k, c := range cnf.Certificates {
|
|
|
|
|
fmt.Printf("CONNECT CERT %d: %v", k, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return svc, err
|
|
|
|
|
}
|
|
|
|
|
@@ -120,19 +138,25 @@ func (s *Service) KV() *consul.KV {
|
|
|
|
|
func (s *Service) healthCheck() (bool, error) {
|
|
|
|
|
alive := func() bool {
|
|
|
|
|
client := &http.Client{}
|
|
|
|
|
healthUrl := s.GetFullAddr() + "health"
|
|
|
|
|
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
|
|
|
|
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
req.Header.Set("User-Agent", "service/internal")
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Sending HEALTH CHECK request to: %s\n", healthUrl)
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Sending HEALTH CHECK request error: %v\n", err)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
var body []byte
|
|
|
|
|
resp.Body.Read(body)
|
|
|
|
|
fmt.Printf("HEALTH CHECK response to: %v -- %v\n", resp, body)
|
|
|
|
|
|
|
|
|
|
return resp.StatusCode == http.StatusOK
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|