Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a9eb0d0732 | |||
| 92b84685c9 | |||
| cd6e62e3bc | |||
| 7cf2d91fd8 | |||
| 936982731d | |||
| 33759c87db | |||
| 974f82e9be | |||
| d7dc75c18f | |||
| c62c63249c | |||
| 6c290eb66b |
@@ -70,12 +70,11 @@ func (s *Service) GetID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetFullAddr() string {
|
func (s *Service) GetFullAddr() string {
|
||||||
isTLS := s.port == 443
|
|
||||||
proto := "http"
|
proto := "http"
|
||||||
if isTLS {
|
if s.tls {
|
||||||
proto = "https"
|
proto = "https"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s://%s:%d/", proto, s.Address, s.port)
|
return fmt.Sprintf("%s://%s:%d/", proto, s.domain, s.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Register() error {
|
func (s *Service) Register() error {
|
||||||
@@ -160,15 +159,17 @@ func (s *Service) healthCheck() (bool, error) {
|
|||||||
alive := func() bool {
|
alive := func() bool {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
||||||
fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
// fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
|
||||||
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", "service/internal")
|
req.Header.Set("User-Agent", "service/internal")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@@ -176,6 +177,8 @@ func (s *Service) healthCheck() (bool, error) {
|
|||||||
var body []byte
|
var body []byte
|
||||||
resp.Body.Read(body)
|
resp.Body.Read(body)
|
||||||
|
|
||||||
|
fmt.Println(resp.StatusCode)
|
||||||
|
|
||||||
return resp.StatusCode == http.StatusOK
|
return resp.StatusCode == http.StatusOK
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -204,8 +207,7 @@ func (s *Service) getTags() []string {
|
|||||||
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
|
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
|
||||||
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.attempts=3",
|
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.attempts=3",
|
||||||
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.statusCode=503",
|
// "treafik.http.middlewares.retryif_" + s.Name + ".plugin.retryif.statusCode=503",
|
||||||
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
|
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`) && PathPrefix(`" + s.pathPrefix + "`)",
|
||||||
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`)",
|
|
||||||
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
||||||
"traefik.http.routers." + s.Name + ".tls=true",
|
"traefik.http.routers." + s.Name + ".tls=true",
|
||||||
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
||||||
@@ -214,10 +216,10 @@ func (s *Service) getTags() []string {
|
|||||||
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=https",
|
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=https",
|
||||||
"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=true",
|
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=true",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=1s",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=5s",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
|
||||||
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
|
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
|
||||||
"traefik.tls.certificates.certfile=certs/client.cert",
|
"traefik.tls.certificates.certfile=certs/client.crt",
|
||||||
"traefik.tls.certificates.keyfile=certs/client.key",
|
"traefik.tls.certificates.keyfile=certs/client.key",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user