Embed UnroutedHandler into Handler

This commit is contained in:
Marius 2016-03-12 22:01:12 +01:00
parent 4191b2a821
commit 5aa7928111
1 changed files with 4 additions and 11 deletions

View File

@ -8,9 +8,8 @@ import (
// Handler is a ready to use handler with routing (using pat)
type Handler struct {
unroutedHandler *UnroutedHandler
routeHandler http.Handler
CompleteUploads chan FileInfo
*UnroutedHandler
http.Handler
}
// NewHandler creates a routed tus protocol handler. This is the simplest
@ -31,13 +30,12 @@ func NewHandler(config Config) (*Handler, error) {
}
routedHandler := &Handler{
unroutedHandler: handler,
CompleteUploads: handler.CompleteUploads,
UnroutedHandler: handler,
}
mux := pat.New()
routedHandler.routeHandler = handler.Middleware(mux)
routedHandler.Handler = handler.Middleware(mux)
mux.Post("", http.HandlerFunc(handler.PostFile))
mux.Head(":id", http.HandlerFunc(handler.HeadFile))
@ -55,8 +53,3 @@ func NewHandler(config Config) (*Handler, error) {
return routedHandler, nil
}
// ServeHTTP Implements the http.Handler interface.
func (rHandler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rHandler.routeHandler.ServeHTTP(w, r)
}