Update linter
This commit is contained in:
parent
f12c27aa7c
commit
328611c619
157 changed files with 489 additions and 508 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
// Handler is the TCP Handlers interface
|
||||
// Handler is the TCP Handlers interface.
|
||||
type Handler interface {
|
||||
ServeTCP(conn WriteCloser)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ type Handler interface {
|
|||
// ordinary functions as handlers.
|
||||
type HandlerFunc func(conn WriteCloser)
|
||||
|
||||
// ServeTCP serves tcp
|
||||
// ServeTCP serves tcp.
|
||||
func (f HandlerFunc) ServeTCP(conn WriteCloser) {
|
||||
f(conn)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"github.com/containous/traefik/v2/pkg/log"
|
||||
)
|
||||
|
||||
// Proxy forwards a TCP request to a TCP service
|
||||
// Proxy forwards a TCP request to a TCP service.
|
||||
type Proxy struct {
|
||||
target *net.TCPAddr
|
||||
terminationDelay time.Duration
|
||||
}
|
||||
|
||||
// NewProxy creates a new Proxy
|
||||
// NewProxy creates a new Proxy.
|
||||
func NewProxy(address string, terminationDelay time.Duration) (*Proxy, error) {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
|
@ -24,7 +24,7 @@ func NewProxy(address string, terminationDelay time.Duration) (*Proxy, error) {
|
|||
return &Proxy{target: tcpAddr, terminationDelay: terminationDelay}, nil
|
||||
}
|
||||
|
||||
// ServeTCP forwards the connection to a service
|
||||
// ServeTCP forwards the connection to a service.
|
||||
func (p *Proxy) ServeTCP(conn WriteCloser) {
|
||||
log.Debugf("Handling connection from %s", conn.RemoteAddr())
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/containous/traefik/v2/pkg/log"
|
||||
)
|
||||
|
||||
// Router is a TCP router
|
||||
// Router is a TCP router.
|
||||
type Router struct {
|
||||
routingTable map[string]Handler
|
||||
httpForwarder Handler
|
||||
|
@ -25,7 +25,7 @@ type Router struct {
|
|||
hostHTTPTLSConfig map[string]*tls.Config // TLS configs keyed by SNI
|
||||
}
|
||||
|
||||
// ServeTCP forwards the connection to the right TCP/HTTP handler
|
||||
// ServeTCP forwards the connection to the right TCP/HTTP handler.
|
||||
func (r *Router) ServeTCP(conn WriteCloser) {
|
||||
// FIXME -- Check if ProxyProtocol changes the first bytes of the request
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (r *Router) ServeTCP(conn WriteCloser) {
|
|||
}
|
||||
}
|
||||
|
||||
// AddRoute defines a handler for a given sniHost (* is the only valid option)
|
||||
// AddRoute defines a handler for a given sniHost (* is the only valid option).
|
||||
func (r *Router) AddRoute(sniHost string, target Handler) {
|
||||
if r.routingTable == nil {
|
||||
r.routingTable = map[string]Handler{}
|
||||
|
@ -94,7 +94,7 @@ func (r *Router) AddRoute(sniHost string, target Handler) {
|
|||
r.routingTable[strings.ToLower(sniHost)] = target
|
||||
}
|
||||
|
||||
// AddRouteTLS defines a handler for a given sniHost and sets the matching tlsConfig
|
||||
// AddRouteTLS defines a handler for a given sniHost and sets the matching tlsConfig.
|
||||
func (r *Router) AddRouteTLS(sniHost string, target Handler, config *tls.Config) {
|
||||
r.AddRoute(sniHost, &TLSHandler{
|
||||
Next: target,
|
||||
|
@ -102,7 +102,7 @@ func (r *Router) AddRouteTLS(sniHost string, target Handler, config *tls.Config)
|
|||
})
|
||||
}
|
||||
|
||||
// AddRouteHTTPTLS defines a handler for a given sniHost and sets the matching tlsConfig
|
||||
// AddRouteHTTPTLS defines a handler for a given sniHost and sets the matching tlsConfig.
|
||||
func (r *Router) AddRouteHTTPTLS(sniHost string, config *tls.Config) {
|
||||
if r.hostHTTPTLSConfig == nil {
|
||||
r.hostHTTPTLSConfig = map[string]*tls.Config{}
|
||||
|
@ -110,12 +110,12 @@ func (r *Router) AddRouteHTTPTLS(sniHost string, config *tls.Config) {
|
|||
r.hostHTTPTLSConfig[sniHost] = config
|
||||
}
|
||||
|
||||
// AddCatchAllNoTLS defines the fallback tcp handler
|
||||
// AddCatchAllNoTLS defines the fallback tcp handler.
|
||||
func (r *Router) AddCatchAllNoTLS(handler Handler) {
|
||||
r.catchAllNoTLS = handler
|
||||
}
|
||||
|
||||
// GetConn creates a connection proxy with a peeked string
|
||||
// GetConn creates a connection proxy with a peeked string.
|
||||
func (r *Router) GetConn(conn WriteCloser, peeked string) WriteCloser {
|
||||
// FIXME should it really be on Router ?
|
||||
conn = &Conn{
|
||||
|
@ -125,22 +125,22 @@ func (r *Router) GetConn(conn WriteCloser, peeked string) WriteCloser {
|
|||
return conn
|
||||
}
|
||||
|
||||
// GetHTTPHandler gets the attached http handler
|
||||
// GetHTTPHandler gets the attached http handler.
|
||||
func (r *Router) GetHTTPHandler() http.Handler {
|
||||
return r.httpHandler
|
||||
}
|
||||
|
||||
// GetHTTPSHandler gets the attached https handler
|
||||
// GetHTTPSHandler gets the attached https handler.
|
||||
func (r *Router) GetHTTPSHandler() http.Handler {
|
||||
return r.httpsHandler
|
||||
}
|
||||
|
||||
// HTTPForwarder sets the tcp handler that will forward the connections to an http handler
|
||||
// HTTPForwarder sets the tcp handler that will forward the connections to an http handler.
|
||||
func (r *Router) HTTPForwarder(handler Handler) {
|
||||
r.httpForwarder = handler
|
||||
}
|
||||
|
||||
// HTTPSForwarder sets the tcp handler that will forward the TLS connections to an http handler
|
||||
// HTTPSForwarder sets the tcp handler that will forward the TLS connections to an http handler.
|
||||
func (r *Router) HTTPSForwarder(handler Handler) {
|
||||
for sniHost, tlsConf := range r.hostHTTPTLSConfig {
|
||||
r.AddRouteTLS(sniHost, handler, tlsConf)
|
||||
|
@ -152,18 +152,18 @@ func (r *Router) HTTPSForwarder(handler Handler) {
|
|||
}
|
||||
}
|
||||
|
||||
// HTTPHandler attaches http handlers on the router
|
||||
// HTTPHandler attaches http handlers on the router.
|
||||
func (r *Router) HTTPHandler(handler http.Handler) {
|
||||
r.httpHandler = handler
|
||||
}
|
||||
|
||||
// HTTPSHandler attaches https handlers on the router
|
||||
// HTTPSHandler attaches https handlers on the router.
|
||||
func (r *Router) HTTPSHandler(handler http.Handler, config *tls.Config) {
|
||||
r.httpsHandler = handler
|
||||
r.httpsTLSConfig = config
|
||||
}
|
||||
|
||||
// Conn is a connection proxy that handles Peeked bytes
|
||||
// Conn is a connection proxy that handles Peeked bytes.
|
||||
type Conn struct {
|
||||
// Peeked are the bytes that have been read from Conn for the
|
||||
// purposes of route matching, but have not yet been consumed
|
||||
|
@ -177,7 +177,7 @@ type Conn struct {
|
|||
WriteCloser
|
||||
}
|
||||
|
||||
// Read reads bytes from the connection (using the buffer prior to actually reading)
|
||||
// Read reads bytes from the connection (using the buffer prior to actually reading).
|
||||
func (c *Conn) Read(p []byte) (n int, err error) {
|
||||
if len(c.Peeked) > 0 {
|
||||
n = copy(p, c.Peeked)
|
||||
|
@ -259,8 +259,8 @@ type sniSniffConn struct {
|
|||
net.Conn // nil; crash on any unexpected use
|
||||
}
|
||||
|
||||
// Read reads from the underlying reader
|
||||
// Read reads from the underlying reader.
|
||||
func (c sniSniffConn) Read(p []byte) (int, error) { return c.r.Read(p) }
|
||||
|
||||
// Write crashes all the time
|
||||
// Write crashes all the time.
|
||||
func (sniSniffConn) Write(p []byte) (int, error) { return 0, io.EOF }
|
||||
|
|
|
@ -4,12 +4,12 @@ import (
|
|||
"github.com/containous/traefik/v2/pkg/safe"
|
||||
)
|
||||
|
||||
// HandlerSwitcher is a TCP handler switcher
|
||||
// HandlerSwitcher is a TCP handler switcher.
|
||||
type HandlerSwitcher struct {
|
||||
router safe.Safe
|
||||
}
|
||||
|
||||
// ServeTCP forwards the TCP connection to the current active handler
|
||||
// ServeTCP forwards the TCP connection to the current active handler.
|
||||
func (s *HandlerSwitcher) ServeTCP(conn WriteCloser) {
|
||||
handler := s.router.Get()
|
||||
h, ok := handler.(Handler)
|
||||
|
@ -20,7 +20,7 @@ func (s *HandlerSwitcher) ServeTCP(conn WriteCloser) {
|
|||
}
|
||||
}
|
||||
|
||||
// Switch sets the new TCP handler to use for new connections
|
||||
// Switch sets the new TCP handler to use for new connections.
|
||||
func (s *HandlerSwitcher) Switch(handler Handler) {
|
||||
s.router.Set(handler)
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"crypto/tls"
|
||||
)
|
||||
|
||||
// TLSHandler handles TLS connections
|
||||
// TLSHandler handles TLS connections.
|
||||
type TLSHandler struct {
|
||||
Next Handler
|
||||
Config *tls.Config
|
||||
}
|
||||
|
||||
// ServeTCP terminates the TLS connection
|
||||
// ServeTCP terminates the TLS connection.
|
||||
func (t *TLSHandler) ServeTCP(conn WriteCloser) {
|
||||
t.Next.ServeTCP(tls.Server(conn, t.Config))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ type server struct {
|
|||
weight int
|
||||
}
|
||||
|
||||
// WRRLoadBalancer is a naive RoundRobin load balancer for TCP services
|
||||
// WRRLoadBalancer is a naive RoundRobin load balancer for TCP services.
|
||||
type WRRLoadBalancer struct {
|
||||
servers []server
|
||||
lock sync.RWMutex
|
||||
|
@ -20,14 +20,14 @@ type WRRLoadBalancer struct {
|
|||
index int
|
||||
}
|
||||
|
||||
// NewWRRLoadBalancer creates a new WRRLoadBalancer
|
||||
// NewWRRLoadBalancer creates a new WRRLoadBalancer.
|
||||
func NewWRRLoadBalancer() *WRRLoadBalancer {
|
||||
return &WRRLoadBalancer{
|
||||
index: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// ServeTCP forwards the connection to the right service
|
||||
// ServeTCP forwards the connection to the right service.
|
||||
func (b *WRRLoadBalancer) ServeTCP(conn WriteCloser) {
|
||||
if len(b.servers) == 0 {
|
||||
log.WithoutContext().Error("no available server")
|
||||
|
@ -42,13 +42,13 @@ func (b *WRRLoadBalancer) ServeTCP(conn WriteCloser) {
|
|||
next.ServeTCP(conn)
|
||||
}
|
||||
|
||||
// AddServer appends a server to the existing list
|
||||
// AddServer appends a server to the existing list.
|
||||
func (b *WRRLoadBalancer) AddServer(serverHandler Handler) {
|
||||
w := 1
|
||||
b.AddWeightServer(serverHandler, &w)
|
||||
}
|
||||
|
||||
// AddWeightServer appends a server to the existing list with a weight
|
||||
// AddWeightServer appends a server to the existing list with a weight.
|
||||
func (b *WRRLoadBalancer) AddWeightServer(serverHandler Handler, weight *int) {
|
||||
w := 1
|
||||
if weight != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue