register fix

This commit is contained in:
Piotr Biernat 2022-12-01 23:12:53 +01:00
parent ad4368cdf8
commit 34ace207a7

View File

@ -36,11 +36,11 @@ func NewService(serverAddr, appID, appName, ip, domain string, appPort int) (*Se
if err != nil { if err != nil {
return nil, err return nil, err
} }
kv := client.KV() // kv := client.KV()
obj := new(consul.KVPair) // obj := new(consul.KVPair)
obj.Key = "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url" // obj.Key = "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url"
obj.Value = []byte(s.GetFullAddr()) // obj.Value = []byte(s.GetFullAddr())
kv.Put(obj, nil) // kv.Put(obj, nil)
s.ConsulAgent = client.Agent() s.ConsulAgent = client.Agent()
return s, nil return s, nil
@ -93,10 +93,12 @@ func (s *Service) UpdateTTL(service *consul.AgentServiceRegistration) {
if !ok { if !ok {
if err := s.ConsulAgent.FailTTL("service:"+s.GetID(), err.Error()); err != nil { if err := s.ConsulAgent.FailTTL("service:"+s.GetID(), err.Error()); err != nil {
log.Println(err) log.Println(err)
fmt.Println(err)
} }
} else { } else {
if err := s.ConsulAgent.PassTTL("service:"+s.GetID(), "OK"); err != nil { if err := s.ConsulAgent.PassTTL("service:"+s.GetID(), "OK"); err != nil {
log.Println(err) log.Println(err)
fmt.Println(err)
} }
} }
} }
@ -104,7 +106,8 @@ func (s *Service) UpdateTTL(service *consul.AgentServiceRegistration) {
func (s *Service) check() (bool, error) { func (s *Service) check() (bool, error) {
client := &http.Client{} client := &http.Client{}
healthUrl := fmt.Sprintf("http://%s/health", s.GetFullAddr()) healthUrl := fmt.Sprintf("%shealth", s.GetFullAddr())
fmt.Println("HCheck: " + healthUrl)
req, err := http.NewRequest(http.MethodGet, healthUrl, nil) req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
if err != nil { if err != nil {
return false, ErrServiceUnavailable return false, ErrServiceUnavailable
@ -132,7 +135,7 @@ func (s *Service) getMetadata() map[string]string {
// key := "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url" // key := "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url"
// m[key] = s.GetFullAddr() // m[key] = s.GetFullAddr()
fmt.Printf("netadata: %v", m) // fmt.Printf("netadata: %v", m)
return m return m
} }