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 {
return nil, err
}
kv := client.KV()
obj := new(consul.KVPair)
obj.Key = "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url"
obj.Value = []byte(s.GetFullAddr())
kv.Put(obj, nil)
// kv := client.KV()
// obj := new(consul.KVPair)
// obj.Key = "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url"
// obj.Value = []byte(s.GetFullAddr())
// kv.Put(obj, nil)
s.ConsulAgent = client.Agent()
return s, nil
@ -93,10 +93,12 @@ func (s *Service) UpdateTTL(service *consul.AgentServiceRegistration) {
if !ok {
if err := s.ConsulAgent.FailTTL("service:"+s.GetID(), err.Error()); err != nil {
log.Println(err)
fmt.Println(err)
}
} else {
if err := s.ConsulAgent.PassTTL("service:"+s.GetID(), "OK"); err != nil {
log.Println(err)
fmt.Println(err)
}
}
}
@ -104,7 +106,8 @@ func (s *Service) UpdateTTL(service *consul.AgentServiceRegistration) {
func (s *Service) check() (bool, error) {
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)
if err != nil {
return false, ErrServiceUnavailable
@ -132,7 +135,7 @@ func (s *Service) getMetadata() map[string]string {
// key := "traefik/http/services/" + s.Name + "/loadBalancer/servers/0/url"
// m[key] = s.GetFullAddr()
fmt.Printf("netadata: %v", m)
// fmt.Printf("netadata: %v", m)
return m
}