Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d484c0e3b0 | |||
| 7a35d1f44a | |||
| 7bfd048051 | |||
| 1433b69abe | |||
| c49ec85b3b | |||
| bdac1d5bc9 |
@@ -6,6 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.pbiernat.dev/egommerce/go-api-pkg/config"
|
||||||
consul "github.com/hashicorp/consul/api"
|
consul "github.com/hashicorp/consul/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ func newClientConfig(serverAddr string) *consul.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetID() string {
|
func (s *Service) GetID() string {
|
||||||
return fmt.Sprintf("%s_%s", s.Name, s.appID)
|
return fmt.Sprintf("%s:%s", s.Name, s.appID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetFullAddr() string {
|
func (s *Service) GetFullAddr() string {
|
||||||
@@ -91,7 +92,7 @@ func (s *Service) Register() error {
|
|||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(interval)
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
if _, err := s.healthCheck(); err != nil {
|
if _, err := s.healthCheck(); err != nil {
|
||||||
fmt.Printf("TTL Error: %v\n", err)
|
fmt.Printf("TTL Error #: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(s)
|
}(s)
|
||||||
@@ -114,14 +115,17 @@ func (s *Service) healthCheck() (bool, error) {
|
|||||||
alive := func() bool {
|
alive := func() bool {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
healthUrl := s.GetFullAddr() + "health"
|
healthUrl := s.GetFullAddr() + "health"
|
||||||
|
fmt.Printf("Sending request to the %s\n", healthUrl)
|
||||||
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to create new Consul request: %v\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", "Health Check")
|
req.Header.Set("User-Agent", "Health Check")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to send Consul request: %v\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@@ -153,7 +157,7 @@ func (s *Service) getTags() []string {
|
|||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
|
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
|
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
|
||||||
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL="",
|
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", ""),
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authRequestHeaders=Cookie",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authRequestHeaders=Cookie",
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authResponseHeaders=Set-Cookie, Server",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.authResponseHeaders=Set-Cookie, Server",
|
||||||
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
|
// "traefik.http.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
|
||||||
|
|||||||
Reference in New Issue
Block a user