Compare commits

..

14 Commits

Author SHA1 Message Date
706ad5481e Consul catalog refactor 2022-12-24 20:28:37 +01:00
b163480e4a Route fix 2022-12-24 19:47:10 +01:00
ca4d8f8eb5 Route fix 2022-12-24 17:57:59 +01:00
c052904266 Route fix 2022-12-24 17:50:29 +01:00
73447dfa80 Route fix 2022-12-24 17:45:56 +01:00
ebb1eab10b DEBUG change 2022-12-24 17:25:41 +01:00
cb5933ccf0 DEBUG change 2022-12-24 17:10:47 +01:00
e6bec060db DEBUG change 2022-12-24 16:43:19 +01:00
4daefbe1c7 DEBUG change 2022-12-24 16:40:31 +01:00
1271467476 DEBUG change 2022-12-24 16:39:21 +01:00
7a44e3c839 DEBUG change 2022-12-24 16:27:10 +01:00
847bd0e41e router change 2022-12-24 15:09:01 +01:00
31172dee69 CORS off 2022-12-24 08:33:09 +01:00
f5d75ae991 added CORS dev config 2022-12-24 06:07:03 +01:00

View File

@@ -10,24 +10,27 @@ import (
)
type Service struct {
Name string
Address string
appID string
domain string
port int
ttl time.Duration
agent *consul.Agent
kv *consul.KV
Name string
Address string
appID string
domain string
pathPrefix string
port int
ttl time.Duration
agent *consul.Agent
kv *consul.KV
catalog *consul.Catalog
}
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
func NewService(servAddr, id, name, hostname, domain string, appPort int) (*Service, error) {
func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort int) (*Service, error) {
s := new(Service)
s.Name = name
s.Address = hostname
s.appID = id
s.domain = domain
s.pathPrefix = pathPrefix
s.port = appPort
s.ttl = time.Second * 15
@@ -37,6 +40,7 @@ func NewService(servAddr, id, name, hostname, domain string, appPort int) (*Serv
}
s.agent = client.Agent()
s.kv = client.KV()
s.catalog = client.Catalog()
return s, nil
}
@@ -104,6 +108,10 @@ func (s *Service) KV() *consul.KV {
return s.kv
}
func (s *Service) Catalog() *consul.Catalog {
return s.catalog
}
func (s *Service) healthCheck() (bool, error) {
alive := func() bool {
client := &http.Client{}
@@ -139,22 +147,18 @@ func (s *Service) healthCheck() (bool, error) {
func (s *Service) getTags() []string {
tags := []string{
"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 + ".entryPoints=https",
"traefik.http.routers." + s.Name + ".tls=true",
"traefik.http.routers." + s.Name + ".service=" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=compress,requestid",
"traefik.http.routers." + s.Name + ".middlewares=requestid,stripprefix_" + s.Name,
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
"traefik.http.middlewares.compress.compress=true",
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
"traefik.http.middlewares.requestid.plugin.requestid.headerName=X-Request-ID",
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
"traefik.tls.certificates.certfile=/certs/client.cert",
"traefik.tls.certificates.keyfile=/certs/client.key",
// "traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
// "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