traefik/pkg/tcp/switcher.go
Ludovic Fernandez 328611c619
Update linter
2020-05-11 12:06:07 +02:00

27 lines
547 B
Go

package tcp
import (
"github.com/containous/traefik/v2/pkg/safe"
)
// HandlerSwitcher is a TCP handler switcher.
type HandlerSwitcher struct {
router safe.Safe
}
// ServeTCP forwards the TCP connection to the current active handler.
func (s *HandlerSwitcher) ServeTCP(conn WriteCloser) {
handler := s.router.Get()
h, ok := handler.(Handler)
if ok {
h.ServeTCP(conn)
} else {
conn.Close()
}
}
// Switch sets the new TCP handler to use for new connections.
func (s *HandlerSwitcher) Switch(handler Handler) {
s.router.Set(handler)
}