Add a new protocol
Co-authored-by: Gérald Croës <gerald@containo.us>
This commit is contained in:
parent
0ca2149408
commit
4a68d29ce2
231 changed files with 6895 additions and 4395 deletions
|
@ -6,30 +6,30 @@ import (
|
|||
"github.com/containous/traefik/safe"
|
||||
)
|
||||
|
||||
// HandlerSwitcher allows hot switching of http.ServeMux
|
||||
type HandlerSwitcher struct {
|
||||
// HTTPHandlerSwitcher allows hot switching of http.ServeMux
|
||||
type HTTPHandlerSwitcher struct {
|
||||
handler *safe.Safe
|
||||
}
|
||||
|
||||
// NewHandlerSwitcher builds a new instance of HandlerSwitcher
|
||||
func NewHandlerSwitcher(newHandler http.Handler) (hs *HandlerSwitcher) {
|
||||
return &HandlerSwitcher{
|
||||
// NewHandlerSwitcher builds a new instance of HTTPHandlerSwitcher
|
||||
func NewHandlerSwitcher(newHandler http.Handler) (hs *HTTPHandlerSwitcher) {
|
||||
return &HTTPHandlerSwitcher{
|
||||
handler: safe.New(newHandler),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HandlerSwitcher) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
func (h *HTTPHandlerSwitcher) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
handlerBackup := h.handler.Get().(http.Handler)
|
||||
handlerBackup.ServeHTTP(rw, req)
|
||||
}
|
||||
|
||||
// GetHandler returns the current http.ServeMux
|
||||
func (h *HandlerSwitcher) GetHandler() (newHandler http.Handler) {
|
||||
func (h *HTTPHandlerSwitcher) GetHandler() (newHandler http.Handler) {
|
||||
handler := h.handler.Get().(http.Handler)
|
||||
return handler
|
||||
}
|
||||
|
||||
// UpdateHandler safely updates the current http.ServeMux with a new one
|
||||
func (h *HandlerSwitcher) UpdateHandler(newHandler http.Handler) {
|
||||
func (h *HTTPHandlerSwitcher) UpdateHandler(newHandler http.Handler) {
|
||||
h.handler.Set(newHandler)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue