Move code to pkg
This commit is contained in:
parent
bd4c822670
commit
f1b085fa36
465 changed files with 656 additions and 680 deletions
28
pkg/tcp/switcher.go
Normal file
28
pkg/tcp/switcher.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package tcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containous/traefik/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 net.Conn) {
|
||||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue