Skip to content

Commit

Permalink
Embed UnroutedHandler into Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Mar 12, 2016
1 parent 4191b2a commit 5aa7928
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
}

0 comments on commit 5aa7928

Please sign in to comment.