1
0
Fork 0

Update linter

This commit is contained in:
Ludovic Fernandez 2020-05-11 12:06:07 +02:00 committed by GitHub
parent f12c27aa7c
commit 328611c619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 489 additions and 508 deletions

View file

@ -69,7 +69,7 @@ func (c *ConfigurationWatcher) Stop() {
close(c.configurationValidatedChan)
}
// AddListener adds a new listener function used when new configuration is provided
// AddListener adds a new listener function used when new configuration is provided.
func (c *ConfigurationWatcher) AddListener(listener func(dynamic.Configuration)) {
if c.configurationListeners == nil {
c.configurationListeners = make([]func(dynamic.Configuration), 0)

View file

@ -10,7 +10,7 @@ import (
const cookieNameLength = 6
// GetName of a cookie
// GetName of a cookie.
func GetName(cookieName string, backendName string) string {
if len(cookieName) != 0 {
return sanitizeName(cookieName)
@ -19,7 +19,7 @@ func GetName(cookieName string, backendName string) string {
return GenerateName(backendName)
}
// GenerateName Generate a hashed name
// GenerateName Generate a hashed name.
func GenerateName(backendName string) string {
data := []byte("_TRAEFIK_BACKEND_" + backendName)
@ -33,7 +33,7 @@ func GenerateName(backendName string) string {
return fmt.Sprintf("_%x", hash.Sum(nil))[:cookieNameLength]
}
// sanitizeName According to [RFC 2616](https://www.ietf.org/rfc/rfc2616.txt) section 2.2
// sanitizeName According to [RFC 2616](https://www.ietf.org/rfc/rfc2616.txt) section 2.2.
func sanitizeName(backend string) string {
sanitizer := func(r rune) rune {
switch r {

View file

@ -37,7 +37,7 @@ const (
middlewareStackKey middlewareStackType = iota
)
// Builder the middleware builder
// Builder the middleware builder.
type Builder struct {
configs map[string]*runtime.MiddlewareInfo
serviceBuilder serviceBuilder
@ -47,12 +47,12 @@ type serviceBuilder interface {
BuildHTTP(ctx context.Context, serviceName string, responseModifier func(*http.Response) error) (http.Handler, error)
}
// NewBuilder creates a new Builder
// NewBuilder creates a new Builder.
func NewBuilder(configs map[string]*runtime.MiddlewareInfo, serviceBuilder serviceBuilder) *Builder {
return &Builder{configs: configs, serviceBuilder: serviceBuilder}
}
// BuildChain creates a middleware chain
// BuildChain creates a middleware chain.
func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.Chain {
chain := alice.New()
for _, name := range middlewares {
@ -99,7 +99,7 @@ func checkRecursion(ctx context.Context, middlewareName string) (context.Context
return context.WithValue(ctx, middlewareStackKey, append(currentStack, middlewareName)), nil
}
// it is the responsibility of the caller to make sure that b.configs[middlewareName].Middleware exists
// it is the responsibility of the caller to make sure that b.configs[middlewareName].Middleware exists.
func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (alice.Constructor, error) {
config := b.configs[middlewareName]
if config == nil || config.Middleware == nil {

View file

@ -13,7 +13,7 @@ const (
key contextKey = iota
)
// AddInContext Adds the provider name in the context
// AddInContext Adds the provider name in the context.
func AddInContext(ctx context.Context, elementName string) context.Context {
parts := strings.Split(elementName, "@")
if len(parts) == 1 {
@ -39,7 +39,7 @@ func GetQualifiedName(ctx context.Context, elementName string) string {
return elementName
}
// MakeQualifiedName Creates a qualified name for an element
// MakeQualifiedName Creates a qualified name for an element.
func MakeQualifiedName(providerName string, elementName string) string {
return elementName + "@" + providerName
}

View file

@ -33,7 +33,7 @@ type serviceManager interface {
LaunchHealthCheck()
}
// Manager A route/router manager
// Manager A route/router manager.
type Manager struct {
routerHandlers map[string]http.Handler
serviceManager serviceManager
@ -43,7 +43,7 @@ type Manager struct {
conf *runtime.Configuration
}
// NewManager Creates a new Manager
// NewManager Creates a new Manager.
func NewManager(conf *runtime.Configuration,
serviceManager serviceManager,
middlewaresBuilder middlewareBuilder,
@ -68,7 +68,7 @@ func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls
return make(map[string]map[string]*runtime.RouterInfo)
}
// BuildHandlers Builds handler for all entry points
// BuildHandlers Builds handler for all entry points.
func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string, tls bool) map[string]http.Handler {
entryPointHandlers := make(map[string]http.Handler)

View file

@ -21,7 +21,7 @@ const (
defaultTLSStoreName = "default"
)
// NewManager Creates a new Manager
// NewManager Creates a new Manager.
func NewManager(conf *runtime.Configuration,
serviceManager *tcpservice.Manager,
httpHandlers map[string]http.Handler,
@ -37,7 +37,7 @@ func NewManager(conf *runtime.Configuration,
}
}
// Manager is a route/router manager
// Manager is a route/router manager.
type Manager struct {
serviceManager *tcpservice.Manager
httpHandlers map[string]http.Handler
@ -62,7 +62,7 @@ func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls
return make(map[string]map[string]*runtime.RouterInfo)
}
// BuildHandlers builds the handlers for the given entrypoints
// BuildHandlers builds the handlers for the given entrypoints.
func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) map[string]*tcp.Router {
entryPointsRouters := m.getTCPRouters(rootCtx, entryPoints)
entryPointsRoutersHTTP := m.getHTTPRouters(rootCtx, entryPoints, true)
@ -117,7 +117,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
domains, err := rules.ParseDomains(routerHTTPConfig.Rule)
if err != nil {
routerErr := fmt.Errorf("invalid rule %s, error: %v", routerHTTPConfig.Rule, err)
routerErr := fmt.Errorf("invalid rule %s, error: %w", routerHTTPConfig.Rule, err)
routerHTTPConfig.AddError(routerErr, true)
logger.Debug(routerErr)
continue

View file

@ -12,7 +12,7 @@ import (
"github.com/containous/traefik/v2/pkg/udp"
)
// NewManager Creates a new Manager
// NewManager Creates a new Manager.
func NewManager(conf *runtime.Configuration,
serviceManager *udpservice.Manager,
) *Manager {
@ -22,7 +22,7 @@ func NewManager(conf *runtime.Configuration,
}
}
// Manager is a route/router manager
// Manager is a route/router manager.
type Manager struct {
serviceManager *udpservice.Manager
conf *runtime.Configuration
@ -36,7 +36,7 @@ func (m *Manager) getUDPRouters(ctx context.Context, entryPoints []string) map[s
return make(map[string]map[string]*runtime.UDPRouterInfo)
}
// BuildHandlers builds the handlers for the given entrypoints
// BuildHandlers builds the handlers for the given entrypoints.
func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) map[string]udp.Handler {
entryPointsRouters := m.getUDPRouters(rootCtx, entryPoints)

View file

@ -31,7 +31,7 @@ type RouterFactory struct {
tlsManager *tls.Manager
}
// NewRouterFactory creates a new RouterFactory
// NewRouterFactory creates a new RouterFactory.
func NewRouterFactory(staticConfiguration static.Configuration, managerFactory *service.ManagerFactory, tlsManager *tls.Manager, chainBuilder *middleware.ChainBuilder) *RouterFactory {
var entryPointsTCP, entryPointsUDP []string
for name, cfg := range staticConfiguration.EntryPoints {
@ -57,7 +57,7 @@ func NewRouterFactory(staticConfiguration static.Configuration, managerFactory *
}
}
// CreateRouters creates new TCPRouters and UDPRouters
// CreateRouters creates new TCPRouters and UDPRouters.
func (f *RouterFactory) CreateRouters(conf dynamic.Configuration) (map[string]*tcpCore.Router, map[string]udpCore.Handler) {
ctx := context.Background()

View file

@ -13,7 +13,7 @@ import (
"github.com/containous/traefik/v2/pkg/server/middleware"
)
// Server is the reverse-proxy/load-balancer engine
// Server is the reverse-proxy/load-balancer engine.
type Server struct {
watcher *ConfigurationWatcher
tcpEntryPoints TCPEntryPoints
@ -47,7 +47,7 @@ func NewServer(routinesPool *safe.Pool, entryPoints TCPEntryPoints, entryPointsU
return srv
}
// Start starts the server and Stop/Close it when context is Done
// Start starts the server and Stop/Close it when context is Done.
func (s *Server) Start(ctx context.Context) {
go func() {
<-ctx.Done()
@ -69,7 +69,7 @@ func (s *Server) Wait() {
<-s.stopChan
}
// Stop stops the server
// Stop stops the server.
func (s *Server) Stop() {
defer log.WithoutContext().Info("Server stopped")
@ -79,7 +79,7 @@ func (s *Server) Stop() {
s.stopChan <- true
}
// Close destroys the server
// Close destroys the server.
func (s *Server) Close() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

View file

@ -37,18 +37,18 @@ func newHTTPForwarder(ln net.Listener) *httpForwarder {
}
}
// ServeTCP uses the connection to serve it later in "Accept"
// ServeTCP uses the connection to serve it later in "Accept".
func (h *httpForwarder) ServeTCP(conn tcp.WriteCloser) {
h.connChan <- conn
}
// Accept retrieves a served connection in ServeTCP
// Accept retrieves a served connection in ServeTCP.
func (h *httpForwarder) Accept() (net.Conn, error) {
conn := <-h.connChan
return conn, nil
}
// TCPEntryPoints holds a map of TCPEntryPoint (the entrypoint names being the keys)
// TCPEntryPoints holds a map of TCPEntryPoint (the entrypoint names being the keys).
type TCPEntryPoints map[string]*TCPEntryPoint
// NewTCPEntryPoints creates a new TCPEntryPoints.
@ -57,7 +57,7 @@ func NewTCPEntryPoints(entryPointsConfig static.EntryPoints) (TCPEntryPoints, er
for entryPointName, config := range entryPointsConfig {
protocol, err := config.GetProtocol()
if err != nil {
return nil, fmt.Errorf("error while building entryPoint %s: %v", entryPointName, err)
return nil, fmt.Errorf("error while building entryPoint %s: %w", entryPointName, err)
}
if protocol != "tcp" {
@ -68,7 +68,7 @@ func NewTCPEntryPoints(entryPointsConfig static.EntryPoints) (TCPEntryPoints, er
serverEntryPointsTCP[entryPointName], err = NewTCPEntryPoint(ctx, config)
if err != nil {
return nil, fmt.Errorf("error while building entryPoint %s: %v", entryPointName, err)
return nil, fmt.Errorf("error while building entryPoint %s: %w", entryPointName, err)
}
}
return serverEntryPointsTCP, nil
@ -109,7 +109,7 @@ func (eps TCPEntryPoints) Switch(routersTCP map[string]*tcp.Router) {
}
}
// TCPEntryPoint is the TCP server
// TCPEntryPoint is the TCP server.
type TCPEntryPoint struct {
listener net.Listener
switcher *tcp.HandlerSwitcher
@ -119,27 +119,27 @@ type TCPEntryPoint struct {
httpsServer *httpServer
}
// NewTCPEntryPoint creates a new TCPEntryPoint
// NewTCPEntryPoint creates a new TCPEntryPoint.
func NewTCPEntryPoint(ctx context.Context, configuration *static.EntryPoint) (*TCPEntryPoint, error) {
tracker := newConnectionTracker()
listener, err := buildListener(ctx, configuration)
if err != nil {
return nil, fmt.Errorf("error preparing server: %v", err)
return nil, fmt.Errorf("error preparing server: %w", err)
}
router := &tcp.Router{}
httpServer, err := createHTTPServer(ctx, listener, configuration, true)
if err != nil {
return nil, fmt.Errorf("error preparing httpServer: %v", err)
return nil, fmt.Errorf("error preparing httpServer: %w", err)
}
router.HTTPForwarder(httpServer.Forwarder)
httpsServer, err := createHTTPServer(ctx, listener, configuration, false)
if err != nil {
return nil, fmt.Errorf("error preparing httpsServer: %v", err)
return nil, fmt.Errorf("error preparing httpsServer: %w", err)
}
router.HTTPSForwarder(httpsServer.Forwarder)
@ -201,7 +201,7 @@ func (e *TCPEntryPoint) Start(ctx context.Context) {
}
}
// Shutdown stops the TCP connections
// Shutdown stops the TCP connections.
func (e *TCPEntryPoint) Shutdown(ctx context.Context) {
logger := log.FromContext(ctx)
@ -381,7 +381,7 @@ func buildListener(ctx context.Context, entryPoint *static.EntryPoint) (net.List
listener, err := net.Listen("tcp", entryPoint.GetAddress())
if err != nil {
return nil, fmt.Errorf("error opening listener: %v", err)
return nil, fmt.Errorf("error opening listener: %w", err)
}
listener = tcpKeepAliveListener{listener.(*net.TCPListener)}
@ -389,7 +389,7 @@ func buildListener(ctx context.Context, entryPoint *static.EntryPoint) (net.List
if entryPoint.ProxyProtocol != nil {
listener, err = buildProxyProtocolListener(ctx, entryPoint, listener)
if err != nil {
return nil, fmt.Errorf("error creating proxy protocol listener: %v", err)
return nil, fmt.Errorf("error creating proxy protocol listener: %w", err)
}
}
return listener, nil
@ -406,14 +406,14 @@ type connectionTracker struct {
lock sync.RWMutex
}
// AddConnection add a connection in the tracked connections list
// AddConnection add a connection in the tracked connections list.
func (c *connectionTracker) AddConnection(conn net.Conn) {
c.lock.Lock()
defer c.lock.Unlock()
c.conns[conn] = struct{}{}
}
// RemoveConnection remove a connection from the tracked connections list
// RemoveConnection remove a connection from the tracked connections list.
func (c *connectionTracker) RemoveConnection(conn net.Conn) {
c.lock.Lock()
defer c.lock.Unlock()
@ -426,7 +426,7 @@ func (c *connectionTracker) isEmpty() bool {
return len(c.conns) == 0
}
// Shutdown wait for the connection closing
// Shutdown wait for the connection closing.
func (c *connectionTracker) Shutdown(ctx context.Context) error {
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
@ -442,7 +442,7 @@ func (c *connectionTracker) Shutdown(ctx context.Context) error {
}
}
// Close close all the connections in the tracked connections list
// Close close all the connections in the tracked connections list.
func (c *connectionTracker) Close() {
c.lock.Lock()
defer c.lock.Unlock()

View file

@ -21,7 +21,7 @@ func NewUDPEntryPoints(cfg static.EntryPoints) (UDPEntryPoints, error) {
for entryPointName, entryPoint := range cfg {
protocol, err := entryPoint.GetProtocol()
if err != nil {
return nil, fmt.Errorf("error while building entryPoint %s: %v", entryPointName, err)
return nil, fmt.Errorf("error while building entryPoint %s: %w", entryPointName, err)
}
if protocol != "udp" {
@ -30,7 +30,7 @@ func NewUDPEntryPoints(cfg static.EntryPoints) (UDPEntryPoints, error) {
ep, err := NewUDPEntryPoint(entryPoint)
if err != nil {
return nil, fmt.Errorf("error while building entryPoint %s: %v", entryPointName, err)
return nil, fmt.Errorf("error while building entryPoint %s: %w", entryPointName, err)
}
entryPoints[entryPointName] = ep
}

View file

@ -15,10 +15,10 @@ import (
"github.com/containous/traefik/v2/pkg/types"
)
// StatusClientClosedRequest non-standard HTTP status code for client disconnection
// StatusClientClosedRequest non-standard HTTP status code for client disconnection.
const StatusClientClosedRequest = 499
// StatusClientClosedRequestText non-standard HTTP status for client disconnection
// StatusClientClosedRequestText non-standard HTTP status for client disconnection.
const StatusClientClosedRequestText = "Client Closed Request"
func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwarding, defaultRoundTripper http.RoundTripper, bufferPool httputil.BufferPool, responseModifier func(*http.Response) error) (http.Handler, error) {
@ -26,7 +26,7 @@ func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwar
if responseForwarding != nil {
err := flushInterval.Set(responseForwarding.FlushInterval)
if err != nil {
return nil, fmt.Errorf("error creating flush interval: %v", err)
return nil, fmt.Errorf("error creating flush interval: %w", err)
}
}
if flushInterval == 0 {

View file

@ -35,7 +35,7 @@ const (
const defaultMaxBodySize int64 = -1
// NewManager creates a new Manager
// NewManager creates a new Manager.
func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper http.RoundTripper, metricsRegistry metrics.Registry, routinePool *safe.Pool) *Manager {
return &Manager{
routinePool: routinePool,
@ -47,7 +47,7 @@ func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper htt
}
}
// Manager The service manager
// Manager The service manager.
type Manager struct {
routinePool *safe.Pool
metricsRegistry metrics.Registry
@ -314,7 +314,7 @@ func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, servi
lbsu := healthcheck.NewLBStatusUpdater(lb, m.configs[serviceName])
if err := m.upsertServers(ctx, lbsu, service.Servers); err != nil {
return nil, fmt.Errorf("error configuring load balancer for service %s: %v", serviceName, err)
return nil, fmt.Errorf("error configuring load balancer for service %s: %w", serviceName, err)
}
return lbsu, nil
@ -326,13 +326,13 @@ func (m *Manager) upsertServers(ctx context.Context, lb healthcheck.BalancerHand
for name, srv := range servers {
u, err := url.Parse(srv.URL)
if err != nil {
return fmt.Errorf("error parsing server URL %s: %v", srv.URL, err)
return fmt.Errorf("error parsing server URL %s: %w", srv.URL, err)
}
logger.WithField(log.ServerName, name).Debugf("Creating server %d %s", name, u)
if err := lb.UpsertServer(u, roundrobin.Weight(1)); err != nil {
return fmt.Errorf("error adding server %s to load balancer: %v", srv.URL, err)
return fmt.Errorf("error adding server %s to load balancer: %w", srv.URL, err)
}
// FIXME Handle Metrics

View file

@ -13,12 +13,12 @@ import (
"github.com/containous/traefik/v2/pkg/tcp"
)
// Manager is the TCPHandlers factory
// Manager is the TCPHandlers factory.
type Manager struct {
configs map[string]*runtime.TCPServiceInfo
}
// NewManager creates a new manager
// NewManager creates a new manager.
func NewManager(conf *runtime.Configuration) *Manager {
return &Manager{
configs: conf.TCPServices,

View file

@ -17,7 +17,7 @@ type Manager struct {
configs map[string]*runtime.UDPServiceInfo
}
// NewManager creates a new manager
// NewManager creates a new manager.
func NewManager(conf *runtime.Configuration) *Manager {
return &Manager{
configs: conf.UDPServices,