refactor: applies linting.
This commit is contained in:
parent
54ca0ce34f
commit
115ddc6a4a
20 changed files with 111 additions and 111 deletions
|
@ -3,6 +3,21 @@
|
||||||
|
|
||||||
skip-files = [
|
skip-files = [
|
||||||
"^old/.*",
|
"^old/.*",
|
||||||
|
"^acme/.*",
|
||||||
|
"^cluster/.*",
|
||||||
|
"^cmd/convert/.*",
|
||||||
|
"^h2c/.*",
|
||||||
|
"^integration/.*",
|
||||||
|
|
||||||
|
# "^cmd/traefik/.*",
|
||||||
|
# "^anonymize/.*",
|
||||||
|
# "^provider/.*",
|
||||||
|
# "^tracing/.*",
|
||||||
|
# "^safe/.*",
|
||||||
|
# "^h2c/.*",
|
||||||
|
# "^healthcheck/.*",
|
||||||
|
# "^middlewares/.*",
|
||||||
|
# "^server/.*",
|
||||||
]
|
]
|
||||||
|
|
||||||
[linters-settings]
|
[linters-settings]
|
||||||
|
@ -21,7 +36,7 @@
|
||||||
|
|
||||||
[linters-settings.goconst]
|
[linters-settings.goconst]
|
||||||
min-len = 3.0
|
min-len = 3.0
|
||||||
min-occurrences = 3.0
|
min-occurrences = 4.0
|
||||||
|
|
||||||
[linters-settings.misspell]
|
[linters-settings.misspell]
|
||||||
locale = "US"
|
locale = "US"
|
||||||
|
@ -34,12 +49,18 @@
|
||||||
"gas",
|
"gas",
|
||||||
"dupl",
|
"dupl",
|
||||||
"prealloc",
|
"prealloc",
|
||||||
|
"gochecknoinits",
|
||||||
|
"gochecknoglobals",
|
||||||
|
"unparam",
|
||||||
|
"scopelint",
|
||||||
|
"goimports",
|
||||||
]
|
]
|
||||||
|
|
||||||
[issues]
|
[issues]
|
||||||
max-per-linter = 0
|
max-per-linter = 0
|
||||||
max-same = 0
|
max-same = 0
|
||||||
exclude = [
|
exclude = [
|
||||||
|
"field `(foo|fuu)` is unused",
|
||||||
"(.+) is deprecated:",
|
"(.+) is deprecated:",
|
||||||
"cyclomatic complexity (\\d+) of func `\\(\\*Builder\\)\\.buildConstructor` is high", #alt/server/middleware/middlewares.go
|
"cyclomatic complexity (\\d+) of func `\\(\\*Builder\\)\\.buildConstructor` is high", #alt/server/middleware/middlewares.go
|
||||||
"`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`", # alt/middlewares/recovery/recovery.go:
|
"`logger` can be `github.com/containous/traefik/vendor/github.com/stretchr/testify/assert.TestingT`", # alt/middlewares/recovery/recovery.go:
|
||||||
|
|
|
@ -155,15 +155,15 @@ func sendReport(body string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func openBrowser(URL string) error {
|
func openBrowser(u string) error {
|
||||||
var err error
|
var err error
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
err = exec.Command("xdg-open", URL).Start()
|
err = exec.Command("xdg-open", u).Start()
|
||||||
case "windows":
|
case "windows":
|
||||||
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", URL).Start()
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", u).Start()
|
||||||
case "darwin":
|
case "darwin":
|
||||||
err = exec.Command("open", URL).Start()
|
err = exec.Command("open", u).Start()
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unsupported platform")
|
err = fmt.Errorf("unsupported platform")
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ func runCmd(staticConfiguration *static.Configuration, configFile string) error
|
||||||
log.WithoutContext().Errorf("Could not enable Watchdog: %v", err)
|
log.WithoutContext().Errorf("Could not enable Watchdog: %v", err)
|
||||||
} else if t != 0 {
|
} else if t != 0 {
|
||||||
// Send a ping each half time given
|
// Send a ping each half time given
|
||||||
t = t / 2
|
t /= 2
|
||||||
log.WithoutContext().Infof("Watchdog activated with timer duration %s", t)
|
log.WithoutContext().Infof("Watchdog activated with timer duration %s", t)
|
||||||
safe.Go(func() {
|
safe.Go(func() {
|
||||||
tick := time.Tick(t)
|
tick := time.Tick(t)
|
||||||
|
|
|
@ -116,7 +116,9 @@ func makeEntryPointTLS(result map[string]string) (*tls.TLS, error) {
|
||||||
if configTLS != nil {
|
if configTLS != nil {
|
||||||
if len(result["ca"]) > 0 {
|
if len(result["ca"]) > 0 {
|
||||||
files := tls.FilesOrContents{}
|
files := tls.FilesOrContents{}
|
||||||
files.Set(result["ca"])
|
if err := files.Set(result["ca"]); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
optional := toBool(result, "ca_optional")
|
optional := toBool(result, "ca_optional")
|
||||||
configTLS.ClientCA = tls.ClientCA{
|
configTLS.ClientCA = tls.ClientCA{
|
||||||
Files: files,
|
Files: files,
|
||||||
|
|
|
@ -334,12 +334,10 @@ func (c *Configuration) ValidateConfiguration() {
|
||||||
if c.ACME != nil {
|
if c.ACME != nil {
|
||||||
if _, ok := c.EntryPoints[c.ACME.EntryPoint]; !ok {
|
if _, ok := c.EntryPoints[c.ACME.EntryPoint]; !ok {
|
||||||
log.Fatalf("Unknown entrypoint %q for ACME configuration", c.ACME.EntryPoint)
|
log.Fatalf("Unknown entrypoint %q for ACME configuration", c.ACME.EntryPoint)
|
||||||
} else {
|
} else if c.EntryPoints[c.ACME.EntryPoint].TLS == nil {
|
||||||
if c.EntryPoints[c.ACME.EntryPoint].TLS == nil {
|
|
||||||
log.Fatalf("Entrypoint %q has no TLS configuration for ACME configuration", c.ACME.EntryPoint)
|
log.Fatalf("Entrypoint %q has no TLS configuration for ACME configuration", c.ACME.EntryPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSafeACMECAServer(caServerSrc string) string {
|
func getSafeACMECAServer(caServerSrc string) string {
|
||||||
|
|
|
@ -132,35 +132,35 @@ func (hc *HealthCheck) checkBackend(backend *BackendConfig) {
|
||||||
var newDisabledURLs []*url.URL
|
var newDisabledURLs []*url.URL
|
||||||
// FIXME re enable metrics
|
// FIXME re enable metrics
|
||||||
for _, disableURL := range backend.disabledURLs {
|
for _, disableURL := range backend.disabledURLs {
|
||||||
//serverUpMetricValue := float64(0)
|
// FIXME serverUpMetricValue := float64(0)
|
||||||
if err := checkHealth(disableURL, backend); err == nil {
|
if err := checkHealth(disableURL, backend); err == nil {
|
||||||
log.Warnf("Health check up: Returning to server list. Backend: %q URL: %q", backend.name, disableURL.String())
|
log.Warnf("Health check up: Returning to server list. Backend: %q URL: %q", backend.name, disableURL.String())
|
||||||
if err := backend.LB.UpsertServer(disableURL, roundrobin.Weight(1)); err != nil {
|
if err = backend.LB.UpsertServer(disableURL, roundrobin.Weight(1)); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
//serverUpMetricValue = 1
|
// FIXME serverUpMetricValue = 1
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("Health check still failing. Backend: %q URL: %q Reason: %s", backend.name, disableURL.String(), err)
|
log.Warnf("Health check still failing. Backend: %q URL: %q Reason: %s", backend.name, disableURL.String(), err)
|
||||||
newDisabledURLs = append(newDisabledURLs, disableURL)
|
newDisabledURLs = append(newDisabledURLs, disableURL)
|
||||||
}
|
}
|
||||||
//labelValues := []string{"backend", backend.name, "url", disableURL.String()}
|
// FIXME labelValues := []string{"backend", backend.name, "url", disableURL.String()}
|
||||||
//hc.metrics.BackendServerUpGauge().With(labelValues...).Set(serverUpMetricValue)
|
// FIXME hc.metrics.BackendServerUpGauge().With(labelValues...).Set(serverUpMetricValue)
|
||||||
}
|
}
|
||||||
backend.disabledURLs = newDisabledURLs
|
backend.disabledURLs = newDisabledURLs
|
||||||
|
|
||||||
// FIXME re enable metrics
|
// FIXME re enable metrics
|
||||||
for _, enableURL := range enabledURLs {
|
for _, enableURL := range enabledURLs {
|
||||||
//serverUpMetricValue := float64(1)
|
// FIXME serverUpMetricValue := float64(1)
|
||||||
if err := checkHealth(enableURL, backend); err != nil {
|
if err := checkHealth(enableURL, backend); err != nil {
|
||||||
log.Warnf("Health check failed: Remove from server list. Backend: %q URL: %q Reason: %s", backend.name, enableURL.String(), err)
|
log.Warnf("Health check failed: Remove from server list. Backend: %q URL: %q Reason: %s", backend.name, enableURL.String(), err)
|
||||||
if err := backend.LB.RemoveServer(enableURL); err != nil {
|
if err := backend.LB.RemoveServer(enableURL); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
backend.disabledURLs = append(backend.disabledURLs, enableURL)
|
backend.disabledURLs = append(backend.disabledURLs, enableURL)
|
||||||
//serverUpMetricValue = 0
|
// FIXME serverUpMetricValue = 0
|
||||||
}
|
}
|
||||||
//labelValues := []string{"backend", backend.name, "url", enableURL.String()}
|
// FIXME labelValues := []string{"backend", backend.name, "url", enableURL.String()}
|
||||||
//hc.metrics.BackendServerUpGauge().With(labelValues...).Set(serverUpMetricValue)
|
// FIXME hc.metrics.BackendServerUpGauge().With(labelValues...).Set(serverUpMetricValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ func (h *Handler) logTheRoundTrip(logDataTable *LogData, crr *captureRequestRead
|
||||||
core[DownstreamContentSize] = crw.Size()
|
core[DownstreamContentSize] = crw.Size()
|
||||||
if original, ok := core[OriginContentSize]; ok {
|
if original, ok := core[OriginContentSize]; ok {
|
||||||
o64 := original.(int64)
|
o64 := original.(int64)
|
||||||
if o64 != crw.Size() && 0 != crw.Size() {
|
if crw.Size() != o64 && crw.Size() != 0 {
|
||||||
core[GzipRatio] = float64(o64) / float64(crw.Size())
|
core[GzipRatio] = float64(o64) / float64(crw.Size())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,19 +167,23 @@ func writeHeader(req *http.Request, forwardReq *http.Request, trustForwardHeader
|
||||||
forwardReq.Header.Set(forward.XForwardedFor, clientIP)
|
forwardReq.Header.Set(forward.XForwardedFor, clientIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
if xMethod := req.Header.Get(xForwardedMethod); xMethod != "" && trustForwardHeader {
|
xMethod := req.Header.Get(xForwardedMethod)
|
||||||
|
switch {
|
||||||
|
case xMethod != "" && trustForwardHeader:
|
||||||
forwardReq.Header.Set(xForwardedMethod, xMethod)
|
forwardReq.Header.Set(xForwardedMethod, xMethod)
|
||||||
} else if req.Method != "" {
|
case req.Method != "":
|
||||||
forwardReq.Header.Set(xForwardedMethod, req.Method)
|
forwardReq.Header.Set(xForwardedMethod, req.Method)
|
||||||
} else {
|
default:
|
||||||
forwardReq.Header.Del(xForwardedMethod)
|
forwardReq.Header.Del(xForwardedMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
if xfp := req.Header.Get(forward.XForwardedProto); xfp != "" && trustForwardHeader {
|
xfp := req.Header.Get(forward.XForwardedProto)
|
||||||
|
switch {
|
||||||
|
case xfp != "" && trustForwardHeader:
|
||||||
forwardReq.Header.Set(forward.XForwardedProto, xfp)
|
forwardReq.Header.Set(forward.XForwardedProto, xfp)
|
||||||
} else if req.TLS != nil {
|
case req.TLS != nil:
|
||||||
forwardReq.Header.Set(forward.XForwardedProto, "https")
|
forwardReq.Header.Set(forward.XForwardedProto, "https")
|
||||||
} else {
|
default:
|
||||||
forwardReq.Header.Set(forward.XForwardedProto, "http")
|
forwardReq.Header.Set(forward.XForwardedProto, "http")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,19 +191,23 @@ func writeHeader(req *http.Request, forwardReq *http.Request, trustForwardHeader
|
||||||
forwardReq.Header.Set(forward.XForwardedPort, xfp)
|
forwardReq.Header.Set(forward.XForwardedPort, xfp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if xfh := req.Header.Get(forward.XForwardedHost); xfh != "" && trustForwardHeader {
|
xfh := req.Header.Get(forward.XForwardedHost)
|
||||||
|
switch {
|
||||||
|
case xfh != "" && trustForwardHeader:
|
||||||
forwardReq.Header.Set(forward.XForwardedHost, xfh)
|
forwardReq.Header.Set(forward.XForwardedHost, xfh)
|
||||||
} else if req.Host != "" {
|
case req.Host != "":
|
||||||
forwardReq.Header.Set(forward.XForwardedHost, req.Host)
|
forwardReq.Header.Set(forward.XForwardedHost, req.Host)
|
||||||
} else {
|
default:
|
||||||
forwardReq.Header.Del(forward.XForwardedHost)
|
forwardReq.Header.Del(forward.XForwardedHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
if xfURI := req.Header.Get(xForwardedURI); xfURI != "" && trustForwardHeader {
|
xfURI := req.Header.Get(xForwardedURI)
|
||||||
|
switch {
|
||||||
|
case xfURI != "" && trustForwardHeader:
|
||||||
forwardReq.Header.Set(xForwardedURI, xfURI)
|
forwardReq.Header.Set(xForwardedURI, xfURI)
|
||||||
} else if req.URL.RequestURI() != "" {
|
case req.URL.RequestURI() != "":
|
||||||
forwardReq.Header.Set(xForwardedURI, req.URL.RequestURI())
|
forwardReq.Header.Set(xForwardedURI, req.URL.RequestURI())
|
||||||
} else {
|
default:
|
||||||
forwardReq.Header.Del(xForwardedURI)
|
forwardReq.Header.Del(xForwardedURI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ func TestSecureHeader(t *testing.T) {
|
||||||
|
|
||||||
func TestSSLForceHost(t *testing.T) {
|
func TestSSLForceHost(t *testing.T) {
|
||||||
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
rw.Write([]byte("OK"))
|
_, _ = rw.Write([]byte("OK"))
|
||||||
})
|
})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
|
|
@ -271,7 +271,8 @@ func getSANs(cert *x509.Certificate) []string {
|
||||||
return sans
|
return sans
|
||||||
}
|
}
|
||||||
|
|
||||||
sans = append(cert.DNSNames, cert.EmailAddresses...)
|
sans = append(sans, cert.DNSNames...)
|
||||||
|
sans = append(sans, cert.EmailAddresses...)
|
||||||
|
|
||||||
var ips []string
|
var ips []string
|
||||||
for _, ip := range cert.IPAddresses {
|
for _, ip := range cert.IPAddresses {
|
||||||
|
|
|
@ -256,7 +256,7 @@ func TestRetryWebsocket(t *testing.T) {
|
||||||
|
|
||||||
forwarder, err := forward.New()
|
forwarder, err := forward.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating forwarder: %s", err)
|
t.Fatalf("Error creating forwarder: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
backendServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
backendServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -274,7 +274,7 @@ func TestRetryWebsocket(t *testing.T) {
|
||||||
|
|
||||||
loadBalancer, err := roundrobin.New(forwarder)
|
loadBalancer, err := roundrobin.New(forwarder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating load balancer: %s", err)
|
t.Fatalf("Error creating load balancer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
basePort := 33444
|
basePort := 33444
|
||||||
|
@ -287,7 +287,10 @@ func TestRetryWebsocket(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the functioning server to the end of the load balancer list
|
// add the functioning server to the end of the load balancer list
|
||||||
loadBalancer.UpsertServer(testhelpers.MustParseURL(backendServer.URL))
|
err = loadBalancer.UpsertServer(testhelpers.MustParseURL(backendServer.URL))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Fail to upsert server: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
retryListener := &countingRetryListener{}
|
retryListener := &countingRetryListener{}
|
||||||
retryH, err := New(context.Background(), loadBalancer, config.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
|
retryH, err := New(context.Background(), loadBalancer, config.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
|
||||||
|
|
|
@ -205,9 +205,7 @@ func (s *LocalStore) RemoveHTTPChallengeToken(token, domain string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := s.storedData.HTTPChallenges[token]; ok {
|
if _, ok := s.storedData.HTTPChallenges[token]; ok {
|
||||||
if _, domainOk := s.storedData.HTTPChallenges[token][domain]; domainOk {
|
|
||||||
delete(s.storedData.HTTPChallenges[token], domain)
|
delete(s.storedData.HTTPChallenges[token], domain)
|
||||||
}
|
|
||||||
if len(s.storedData.HTTPChallenges[token]) == 0 {
|
if len(s.storedData.HTTPChallenges[token]) == 0 {
|
||||||
delete(s.storedData.HTTPChallenges, token)
|
delete(s.storedData.HTTPChallenges, token)
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,8 @@ func (p *Provider) getClient() (*lego.Client, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.DNSChallenge != nil && len(p.DNSChallenge.Provider) > 0 {
|
switch {
|
||||||
|
case p.DNSChallenge != nil && len(p.DNSChallenge.Provider) > 0:
|
||||||
logger.Debugf("Using DNS Challenge provider: %s", p.DNSChallenge.Provider)
|
logger.Debugf("Using DNS Challenge provider: %s", p.DNSChallenge.Provider)
|
||||||
|
|
||||||
var provider challenge.Provider
|
var provider challenge.Provider
|
||||||
|
@ -310,21 +311,23 @@ func (p *Provider) getClient() (*lego.Client, error) {
|
||||||
p.DNSChallenge.preCheckTimeout, p.DNSChallenge.preCheckInterval = challengeProviderTimeout.Timeout()
|
p.DNSChallenge.preCheckTimeout, p.DNSChallenge.preCheckInterval = challengeProviderTimeout.Timeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if p.HTTPChallenge != nil && len(p.HTTPChallenge.EntryPoint) > 0 {
|
case p.HTTPChallenge != nil && len(p.HTTPChallenge.EntryPoint) > 0:
|
||||||
logger.Debug("Using HTTP Challenge provider.")
|
logger.Debug("Using HTTP Challenge provider.")
|
||||||
|
|
||||||
err = client.Challenge.SetHTTP01Provider(&challengeHTTP{Store: p.Store})
|
err = client.Challenge.SetHTTP01Provider(&challengeHTTP{Store: p.Store})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if p.TLSChallenge != nil {
|
|
||||||
|
case p.TLSChallenge != nil:
|
||||||
logger.Debug("Using TLS Challenge provider.")
|
logger.Debug("Using TLS Challenge provider.")
|
||||||
|
|
||||||
err = client.Challenge.SetTLSALPN01Provider(&challengeTLSALPN{Store: p.Store})
|
err = client.Challenge.SetTLSALPN01Provider(&challengeTLSALPN{Store: p.Store})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
default:
|
||||||
return nil, errors.New("ACME challenge not specified, please select TLS or HTTP or DNS Challenge")
|
return nil, errors.New("ACME challenge not specified, please select TLS or HTTP or DNS Challenge")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,11 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/Masterminds/sprig"
|
"github.com/Masterminds/sprig"
|
||||||
"github.com/containous/traefik/autogen/gentemplates"
|
|
||||||
"github.com/containous/traefik/config"
|
"github.com/containous/traefik/config"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
|
@ -88,26 +86,6 @@ func (p *BaseProvider) DecodeConfiguration(content string) (*config.Configuratio
|
||||||
return configuration, nil
|
return configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *BaseProvider) getTemplateContent(defaultTemplateFile string) (string, error) {
|
|
||||||
if len(p.Filename) > 0 {
|
|
||||||
buf, err := ioutil.ReadFile(p.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(buf), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasSuffix(defaultTemplateFile, ".tmpl") {
|
|
||||||
buf, err := gentemplates.Asset(defaultTemplateFile)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(buf), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultTemplateFile, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func split(sep, s string) []string {
|
func split(sep, s string) []string {
|
||||||
return strings.Split(s, sep)
|
return strings.Split(s, sep)
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,11 +139,12 @@ func (p *Provider) getIPPort(ctx context.Context, container dockerData, serverPo
|
||||||
|
|
||||||
if p.UseBindPortIP {
|
if p.UseBindPortIP {
|
||||||
portBinding, err := p.getPortBinding(container, serverPort)
|
portBinding, err := p.getPortBinding(container, serverPort)
|
||||||
if err != nil {
|
switch {
|
||||||
|
case err != nil:
|
||||||
logger.Infof("Unable to find a binding for container %q, falling back on its internal IP/Port.", container.Name)
|
logger.Infof("Unable to find a binding for container %q, falling back on its internal IP/Port.", container.Name)
|
||||||
} else if (portBinding.HostIP == "0.0.0.0") || (len(portBinding.HostIP) == 0) {
|
case portBinding.HostIP == "0.0.0.0" || len(portBinding.HostIP) == 0:
|
||||||
logger.Infof("Cannot determine the IP address (got %q) for %q's binding, falling back on its internal IP/Port.", portBinding.HostIP, container.Name)
|
logger.Infof("Cannot determine the IP address (got %q) for %q's binding, falling back on its internal IP/Port.", portBinding.HostIP, container.Name)
|
||||||
} else {
|
default:
|
||||||
ip = portBinding.HostIP
|
ip = portBinding.HostIP
|
||||||
port = portBinding.HostPort
|
port = portBinding.HostPort
|
||||||
usedBound = true
|
usedBound = true
|
||||||
|
@ -166,9 +167,9 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
|
||||||
logger := log.FromContext(ctx)
|
logger := log.FromContext(ctx)
|
||||||
|
|
||||||
if container.ExtraConf.Docker.Network != "" {
|
if container.ExtraConf.Docker.Network != "" {
|
||||||
networkSettings := container.NetworkSettings
|
settings := container.NetworkSettings
|
||||||
if networkSettings.Networks != nil {
|
if settings.Networks != nil {
|
||||||
network := networkSettings.Networks[container.ExtraConf.Docker.Network]
|
network := settings.Networks[container.ExtraConf.Docker.Network]
|
||||||
if network != nil {
|
if network != nil {
|
||||||
return network.Addr
|
return network.Addr
|
||||||
}
|
}
|
||||||
|
@ -251,11 +252,6 @@ func getPort(container dockerData, serverPort string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape beginning slash "/", convert all others to dash "-", and convert underscores "_" to dash "-"
|
|
||||||
func getSubDomain(name string) string {
|
|
||||||
return strings.NewReplacer("/", "-", "_", "-").Replace(strings.TrimPrefix(name, "/"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getServiceName(container dockerData) string {
|
func getServiceName(container dockerData) string {
|
||||||
serviceName := container.ServiceName
|
serviceName := container.ServiceName
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,12 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
if p.Watch {
|
if p.Watch {
|
||||||
var watchItem string
|
var watchItem string
|
||||||
|
|
||||||
if len(p.Directory) > 0 {
|
switch {
|
||||||
|
case len(p.Directory) > 0:
|
||||||
watchItem = p.Directory
|
watchItem = p.Directory
|
||||||
} else if len(p.Filename) > 0 {
|
case len(p.Filename) > 0:
|
||||||
watchItem = filepath.Dir(p.Filename)
|
watchItem = filepath.Dir(p.Filename)
|
||||||
} else {
|
default:
|
||||||
watchItem = filepath.Dir(p.TraefikFile)
|
watchItem = filepath.Dir(p.TraefikFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,16 +45,16 @@ func (p *Provider) Append(systemRouter *mux.Router) {
|
||||||
|
|
||||||
configuration := new(config.Configuration)
|
configuration := new(config.Configuration)
|
||||||
body, _ := ioutil.ReadAll(request.Body)
|
body, _ := ioutil.ReadAll(request.Body)
|
||||||
err := json.Unmarshal(body, configuration)
|
|
||||||
if err == nil {
|
if err := json.Unmarshal(body, configuration); err != nil {
|
||||||
p.configurationChan <- config.Message{ProviderName: "rest", Configuration: configuration}
|
|
||||||
err := templatesRenderer.JSON(response, http.StatusOK, configuration)
|
|
||||||
if err != nil {
|
|
||||||
log.WithoutContext().Error(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.WithoutContext().Errorf("Error parsing configuration %+v", err)
|
log.WithoutContext().Errorf("Error parsing configuration %+v", err)
|
||||||
http.Error(response, fmt.Sprintf("%+v", err), http.StatusBadRequest)
|
http.Error(response, fmt.Sprintf("%+v", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.configurationChan <- config.Message{ProviderName: "rest", Configuration: configuration}
|
||||||
|
if err := templatesRenderer.JSON(response, http.StatusOK, configuration); err != nil {
|
||||||
|
log.WithoutContext().Error(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ func (s *Server) listenSignals(stop chan bool) {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
case sig := <-s.signals:
|
case sig := <-s.signals:
|
||||||
switch sig {
|
if sig == syscall.SIGUSR1 {
|
||||||
case syscall.SIGUSR1:
|
|
||||||
log.WithoutContext().Infof("Closing and re-opening log files for rotation: %+v", sig)
|
log.WithoutContext().Infof("Closing and re-opening log files for rotation: %+v", sig)
|
||||||
|
|
||||||
if s.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
|
|
|
@ -28,17 +28,6 @@ const (
|
||||||
defaultHealthCheckTimeout = 5 * time.Second
|
defaultHealthCheckTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// See oxy/roundrobin/rr.go
|
|
||||||
type balancerHandler interface {
|
|
||||||
Servers() []*url.URL
|
|
||||||
ServeHTTP(w http.ResponseWriter, req *http.Request)
|
|
||||||
ServerWeight(u *url.URL) (int, bool)
|
|
||||||
RemoveServer(u *url.URL) error
|
|
||||||
UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error
|
|
||||||
NextServer() (*url.URL, error)
|
|
||||||
Next() http.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewManager creates a new Manager
|
// NewManager creates a new Manager
|
||||||
func NewManager(configs map[string]*config.Service, defaultRoundTripper http.RoundTripper) *Manager {
|
func NewManager(configs map[string]*config.Service, defaultRoundTripper http.RoundTripper) *Manager {
|
||||||
return &Manager{
|
return &Manager{
|
||||||
|
@ -148,11 +137,12 @@ func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler
|
||||||
interval := defaultHealthCheckInterval
|
interval := defaultHealthCheckInterval
|
||||||
if hc.Interval != "" {
|
if hc.Interval != "" {
|
||||||
intervalOverride, err := time.ParseDuration(hc.Interval)
|
intervalOverride, err := time.ParseDuration(hc.Interval)
|
||||||
if err != nil {
|
switch {
|
||||||
|
case err != nil:
|
||||||
logger.Errorf("Illegal health check interval for '%s': %s", backend, err)
|
logger.Errorf("Illegal health check interval for '%s': %s", backend, err)
|
||||||
} else if intervalOverride <= 0 {
|
case intervalOverride <= 0:
|
||||||
logger.Errorf("Health check interval smaller than zero for service '%s'", backend)
|
logger.Errorf("Health check interval smaller than zero for service '%s'", backend)
|
||||||
} else {
|
default:
|
||||||
interval = intervalOverride
|
interval = intervalOverride
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,11 +150,12 @@ func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler
|
||||||
timeout := defaultHealthCheckTimeout
|
timeout := defaultHealthCheckTimeout
|
||||||
if hc.Timeout != "" {
|
if hc.Timeout != "" {
|
||||||
timeoutOverride, err := time.ParseDuration(hc.Timeout)
|
timeoutOverride, err := time.ParseDuration(hc.Timeout)
|
||||||
if err != nil {
|
switch {
|
||||||
|
case err != nil:
|
||||||
logger.Errorf("Illegal health check timeout for backend '%s': %s", backend, err)
|
logger.Errorf("Illegal health check timeout for backend '%s': %s", backend, err)
|
||||||
} else if timeoutOverride <= 0 {
|
case timeoutOverride <= 0:
|
||||||
logger.Errorf("Health check timeout smaller than zero for backend '%s', backend", backend)
|
logger.Errorf("Health check timeout smaller than zero for backend '%s', backend", backend)
|
||||||
} else {
|
default:
|
||||||
timeout = timeoutOverride
|
timeout = timeoutOverride
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,14 @@ func NewConstraint(exp string) (*Constraint, error) {
|
||||||
sep := ""
|
sep := ""
|
||||||
constraint := &Constraint{}
|
constraint := &Constraint{}
|
||||||
|
|
||||||
if strings.Contains(exp, "==") {
|
switch {
|
||||||
|
case strings.Contains(exp, "=="):
|
||||||
sep = "=="
|
sep = "=="
|
||||||
constraint.MustMatch = true
|
constraint.MustMatch = true
|
||||||
} else if strings.Contains(exp, "!=") {
|
case strings.Contains(exp, "!="):
|
||||||
sep = "!="
|
sep = "!="
|
||||||
constraint.MustMatch = false
|
constraint.MustMatch = false
|
||||||
} else {
|
default:
|
||||||
return nil, errors.New("constraint expression missing valid operator: '==' or '!='")
|
return nil, errors.New("constraint expression missing valid operator: '==' or '!='")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue