traefik/pkg/udp/switcher.go
Jean-Baptiste Doumenjou c0f1e74bed
chore: move to Traefik organization.
Co-authored-by: Romain <rtribotte@users.noreply.github.com>
2020-09-16 15:46:04 +02:00

26 lines
534 B
Go

package udp
import (
"github.com/traefik/traefik/v2/pkg/safe"
)
// HandlerSwitcher is a switcher implementation of the Handler interface.
type HandlerSwitcher struct {
handler safe.Safe
}
// ServeUDP implements the Handler interface.
func (s *HandlerSwitcher) ServeUDP(conn *Conn) {
handler := s.handler.Get()
h, ok := handler.(Handler)
if ok {
h.ServeUDP(conn)
} else {
conn.Close()
}
}
// Switch replaces s handler with the given handler.
func (s *HandlerSwitcher) Switch(handler Handler) {
s.handler.Set(handler)
}