Compare commits

..

13 Commits

2 changed files with 13 additions and 6 deletions

View File

@@ -3,7 +3,6 @@ package config
import ( import (
"os" "os"
"github.com/gofiber/fiber/v2/log"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
@@ -16,7 +15,7 @@ func init() {
func GetEnv(name string, defVal string) string { func GetEnv(name string, defVal string) string {
env := os.Getenv(name) env := os.Getenv(name)
if env == "" { if env == "" {
log.Panicf("Missing %s env variable", name) return defVal
} }
return env return env

View File

@@ -95,6 +95,11 @@ func (s *Service) Register() error {
return nil return nil
} }
func (s *Service) Unregister() error { func (s *Service) Unregister() error {
// s.client.Catalog().Deregister(&consul.CatalogDeregistration{
// Address: s.Address,
// ServiceID: s.GetID(),
// }, nil)
return s.agent.ServiceDeregister(s.GetID()) return s.agent.ServiceDeregister(s.GetID())
} }
@@ -178,10 +183,10 @@ 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.middlewares.auth_" + s.Name + ".forwardauth.trustForwardHeader=true",
// "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 + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", "http://identity.service.ego.io/api/v1/traefik"),
"traefik.http.middlewares.auth_" + s.Name + ".plugin.auth.handlerURL=" + config.GetEnv("AUTH_HANDLER_URL", ""),
"traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID", "traefik.http.middlewares.requestid_" + s.Name + ".plugin.requestid.headerName=X-Request-ID",
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix, "traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)", "traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
@@ -190,10 +195,13 @@ func (s *Service) getTags() []string {
// "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,
// "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name, // "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",stripprefix_" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + "@docker,requestid_" + s.Name + "@docker,stripprefix_" + s.Name + "@docker", "traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",requestid_" + s.Name + ",stripprefix_" + s.Name + "",
"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=true",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.interval=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.timeout=1s",
"traefik.http.services." + s.Name + ".loadbalancer.healthcheck.path=/health",
"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",
} }