Skip to content

Commit 9f3fe63

Browse files
committed
refactor: remove unnecessary casts to MiddlewareFunc
1 parent 801865f commit 9f3fe63

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

header.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import "net/http"
55
// HeaderMiddleware creates and returns a MiddlewareFunc that will apply all of the headers
66
// that have been passed in.
77
func HeaderMiddleware(headers map[string]string) MiddlewareFunc {
8-
return MiddlewareFunc(func(next Handler) Handler {
8+
return func(next Handler) Handler {
99
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
1010
for key, value := range headers {
1111
w.Header().Add(key, value)
1212
}
1313
return next.ServeHTTPWithError(w, r)
1414
})
15-
})
15+
}
1616
}

httperrorhandler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// error was returned from the handler. This will allow any other middleware to assume
1616
// that if they have not received an error, then no error has occurred.
1717
func HTTPErrorHandlerMiddleware(registeredErrors map[error]int) MiddlewareFunc {
18-
return MiddlewareFunc(func(next Handler) Handler {
18+
return func(next Handler) Handler {
1919
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
2020
cw := NewCaptureWriter(w)
2121
err := next.ServeHTTPWithError(cw, r)
@@ -58,5 +58,5 @@ func HTTPErrorHandlerMiddleware(registeredErrors map[error]int) MiddlewareFunc {
5858
Error(w, err.Error(), http.StatusInternalServerError)
5959
return NewHTTPError(err, http.StatusInternalServerError)
6060
})
61-
})
61+
}
6262
}

timeout.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func NewTimeout(duration time.Duration, message string) Timeout {
3636
// TimeoutMiddleware creates, initialises and returns a middleware function that will wrap the next
3737
// handler in the stack with a timeout handler.
3838
func TimeoutMiddleware(timeout Timeout) MiddlewareFunc {
39-
return MiddlewareFunc(func(next Handler) Handler {
39+
return func(next Handler) Handler {
4040
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
4141
th := NewTimeoutHandler(next, timeout)
4242
return th.ServeHTTPWithError(w, r)
4343
})
44-
})
44+
}
4545
}
4646

4747
// ------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)