1
0
Fork 0

refactor: applies linting.

This commit is contained in:
Ludovic Fernandez 2019-02-05 17:10:03 +01:00 committed by Traefiker Bot
parent 54ca0ce34f
commit 115ddc6a4a
20 changed files with 111 additions and 111 deletions

View file

@ -205,9 +205,7 @@ func (s *LocalStore) RemoveHTTPChallengeToken(token, domain string) error {
}
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 {
delete(s.storedData.HTTPChallenges, token)
}

View file

@ -277,7 +277,8 @@ func (p *Provider) getClient() (*lego.Client, error) {
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)
var provider challenge.Provider
@ -310,21 +311,23 @@ func (p *Provider) getClient() (*lego.Client, error) {
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.")
err = client.Challenge.SetHTTP01Provider(&challengeHTTP{Store: p.Store})
if err != nil {
return nil, err
}
} else if p.TLSChallenge != nil {
case p.TLSChallenge != nil:
logger.Debug("Using TLS Challenge provider.")
err = client.Challenge.SetTLSALPN01Provider(&challengeTLSALPN{Store: p.Store})
if err != nil {
return nil, err
}
} else {
default:
return nil, errors.New("ACME challenge not specified, please select TLS or HTTP or DNS Challenge")
}

View file

@ -2,13 +2,11 @@ package provider
import (
"bytes"
"io/ioutil"
"strings"
"text/template"
"github.com/BurntSushi/toml"
"github.com/Masterminds/sprig"
"github.com/containous/traefik/autogen/gentemplates"
"github.com/containous/traefik/config"
"github.com/containous/traefik/log"
"github.com/containous/traefik/types"
@ -88,26 +86,6 @@ func (p *BaseProvider) DecodeConfiguration(content string) (*config.Configuratio
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 {
return strings.Split(s, sep)
}

View file

@ -139,11 +139,12 @@ func (p *Provider) getIPPort(ctx context.Context, container dockerData, serverPo
if p.UseBindPortIP {
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)
} 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)
} else {
default:
ip = portBinding.HostIP
port = portBinding.HostPort
usedBound = true
@ -166,9 +167,9 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
logger := log.FromContext(ctx)
if container.ExtraConf.Docker.Network != "" {
networkSettings := container.NetworkSettings
if networkSettings.Networks != nil {
network := networkSettings.Networks[container.ExtraConf.Docker.Network]
settings := container.NetworkSettings
if settings.Networks != nil {
network := settings.Networks[container.ExtraConf.Docker.Network]
if network != nil {
return network.Addr
}
@ -251,11 +252,6 @@ func getPort(container dockerData, serverPort string) string {
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 {
serviceName := container.ServiceName

View file

@ -47,11 +47,12 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
if p.Watch {
var watchItem string
if len(p.Directory) > 0 {
switch {
case len(p.Directory) > 0:
watchItem = p.Directory
} else if len(p.Filename) > 0 {
case len(p.Filename) > 0:
watchItem = filepath.Dir(p.Filename)
} else {
default:
watchItem = filepath.Dir(p.TraefikFile)
}

View file

@ -45,16 +45,16 @@ func (p *Provider) Append(systemRouter *mux.Router) {
configuration := new(config.Configuration)
body, _ := ioutil.ReadAll(request.Body)
err := json.Unmarshal(body, configuration)
if 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 {
if err := json.Unmarshal(body, configuration); err != nil {
log.WithoutContext().Errorf("Error parsing configuration %+v", err)
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)
}
})
}