Consul catalog refactor
This commit is contained in:
parent
b163480e4a
commit
706ad5481e
@ -19,6 +19,7 @@ type Service struct {
|
|||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
agent *consul.Agent
|
agent *consul.Agent
|
||||||
kv *consul.KV
|
kv *consul.KV
|
||||||
|
catalog *consul.Catalog
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
||||||
@ -39,6 +40,7 @@ func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort
|
|||||||
}
|
}
|
||||||
s.agent = client.Agent()
|
s.agent = client.Agent()
|
||||||
s.kv = client.KV()
|
s.kv = client.KV()
|
||||||
|
s.catalog = client.Catalog()
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@ -106,6 +108,10 @@ func (s *Service) KV() *consul.KV {
|
|||||||
return s.kv
|
return s.kv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) Catalog() *consul.Catalog {
|
||||||
|
return s.catalog
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) healthCheck() (bool, error) {
|
func (s *Service) healthCheck() (bool, error) {
|
||||||
alive := func() bool {
|
alive := func() bool {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
@ -141,7 +147,6 @@ func (s *Service) healthCheck() (bool, error) {
|
|||||||
func (s *Service) getTags() []string {
|
func (s *Service) getTags() []string {
|
||||||
tags := []string{
|
tags := []string{
|
||||||
"traefik.enable=true",
|
"traefik.enable=true",
|
||||||
// "traefik.http.routers." + s.Name + ".rule=Header(`X-API-SERVICE`, `" + s.Name + "`)",
|
|
||||||
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
|
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
|
||||||
"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",
|
||||||
@ -154,10 +159,6 @@ func (s *Service) getTags() []string {
|
|||||||
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
|
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
|
||||||
"traefik.tls.certificates.certfile=/certs/client.cert",
|
"traefik.tls.certificates.certfile=/certs/client.cert",
|
||||||
"traefik.tls.certificates.keyfile=/certs/client.key",
|
"traefik.tls.certificates.keyfile=/certs/client.key",
|
||||||
// "traefik.http.services." + s.Name + ".loadbalancer.servers." + fullName + "=" + bFullAddr,
|
|
||||||
// "traefik.http.services." + s.Name + ".loadbalancer.servers." + fullName + ".url=" + bFullAddr,
|
|
||||||
// "traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
|
|
||||||
// "traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=10s",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
Loading…
Reference in New Issue
Block a user