Skip to content

Commit

Permalink
removed parent field from Middleware struct
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmashko committed Jun 26, 2020
1 parent 95f3d7d commit 1bafa51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ mw := ruffe.NewMiddlewareFunc(func(_ ruffe.Context) error {
})

// Add middleware handler before calling <ruffe handler>
mwh := mw.Wrap(<ruffe handler>) // WrapFunc returns middleware
mwh := mw.Before(<ruffe handler>) // WrapFunc returns middleware

// Add middleware handler after calling <ruffe handler>
mwh := mw.WrapAfter(<ruffe handler>) // WrapAfterFunc returns middleware
mwh := mw.After(<ruffe handler>) // WrapAfterFunc returns middleware
```
#### Router middleware
```go
Expand Down
14 changes: 7 additions & 7 deletions middleware.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ruffe

type Middleware struct {
parent *Middleware
h Handler
OnError func(Context, error) error
}
Expand All @@ -16,32 +15,33 @@ func NewMiddlewareFunc(f func(Context) error) *Middleware {
return NewMiddleware(HandlerFunc(f))
}

// Before create middleware which call Middleware handler before handler from argument
func (m *Middleware) Before(h Handler) *Middleware {
return &Middleware{
parent: m,
h: m.mwf(m.h, h),
h: m.mwf(m.h, h),
}
}

// BeforeFunc do same as Before
func (m *Middleware) BeforeFunc(f func(Context) error) *Middleware {
return m.Before(HandlerFunc(f))
}

// WrapAfter invoke middleware handler after wrapped handler
// After create middleware which call Middleware handler after handler from argument
func (m *Middleware) After(h Handler) *Middleware {
return &Middleware{
parent: m,
h: m.mwf(h, m.h),
h: m.mwf(h, m.h),
}
}

// AfterFunc do same as After
func (m *Middleware) AfterFunc(f func(Context) error) *Middleware {
return m.After(HandlerFunc(f))
}

// Wrap crate middleware from f argument where pass Middleware handler as next argument
func (m *Middleware) Wrap(f func(ctx Context, next Handler) error) *Middleware {
return &Middleware{
parent: m,
h: HandlerFunc(func(ctx Context) error {
if ctx.done() {
return nil
Expand Down

0 comments on commit 1bafa51

Please sign in to comment.