Skip to content

Commit

Permalink
add some new method alias, will not support go 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 21, 2022
1 parent 15d9eb4 commit 9627aa4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: [1.13, 1.14, 1.15, 1.16]
go_version: [1.14, 1.15, 1.16, 1.17]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: [1.15]
go: [1.16]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gookit/rux

go 1.13
go 1.14

require (
github.com/gookit/color v1.5.0
Expand Down
18 changes: 14 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,34 @@ func (c HandlersChain) Last() HandlerFunc {
return nil
}

// HTTPHandler warp an generic http.Handler as an middleware HandlerFunc
// WrapH warp an generic http.Handler as an rux HandlerFunc
func WrapH(hh http.Handler) HandlerFunc {
return WrapHTTPHandler(hh)
}

// HTTPHandler warp a generic http.Handler as an rux HandlerFunc
func HTTPHandler(gh http.Handler) HandlerFunc {
return WrapHTTPHandler(gh)
}

// WrapHTTPHandler warp an generic http.Handler as an middleware HandlerFunc
// WrapHTTPHandler warp a generic http.Handler as an rux HandlerFunc
func WrapHTTPHandler(gh http.Handler) HandlerFunc {
return func(c *Context) {
gh.ServeHTTP(c.Resp, c.Req)
}
}

// HTTPHandlerFunc warp an generic http.HandlerFunc as an middleware HandlerFunc
// WrapHF warp a generic http.HandlerFunc as a rux HandlerFunc
func WrapHF(hf http.HandlerFunc) HandlerFunc {
return WrapHTTPHandlerFunc(hf)
}

// HTTPHandlerFunc warp a generic http.HandlerFunc as a rux HandlerFunc
func HTTPHandlerFunc(hf http.HandlerFunc) HandlerFunc {
return WrapHTTPHandlerFunc(hf)
}

// WrapHTTPHandlerFunc warp an generic http.HandlerFunc as an middleware HandlerFunc
// WrapHTTPHandlerFunc warp a generic http.HandlerFunc as a rux HandlerFunc
func WrapHTTPHandlerFunc(hf http.HandlerFunc) HandlerFunc {
return func(c *Context) {
hf(c.Resp, c.Req)
Expand Down
4 changes: 2 additions & 2 deletions middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestWrapHTTPHandler(t *testing.T) {
r.GET("/path", func(c *Context) {
c.WriteString("o")
}).Use(
HTTPHandler(gh),
WrapH(gh),
WrapHTTPHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("ll"))
})))
Expand All @@ -337,7 +337,7 @@ func TestWrapHTTPHandler(t *testing.T) {
r.GET("/path1", func(c *Context) {
c.WriteString("o")
}).Use(
HTTPHandlerFunc(gh),
WrapHF(gh),
WrapHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("ll"))
}))
Expand Down

0 comments on commit 9627aa4

Please sign in to comment.