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