File tree Expand file tree Collapse file tree 6 files changed +32
-9
lines changed Expand file tree Collapse file tree 6 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -53,9 +53,9 @@ func (f *Func) buildMeta() {
53
53
case Handler :
54
54
f .Meta = & FuncMeta {Handler : fn }
55
55
return
56
- case func (* Context ):
57
- f .Meta = & FuncMeta {Handler : fn }
58
- return
56
+ // case func(*Context):
57
+ // f.Meta = &FuncMeta{Handler: fn}
58
+ // return
59
59
case func (* Context ) error :
60
60
f .Meta = & FuncMeta {HandlerWithErr : fn }
61
61
return
Original file line number Diff line number Diff line change @@ -104,12 +104,12 @@ func (expr *NameExpr) MatchString(s string) bool {
104
104
//
105
105
// If Handler panics, the server (the caller of Handler) assumes that the effect of the panic was isolated to the active request.
106
106
// It recovers the panic, logs a stack trace to the server error log, and hangs up the connection.
107
- type Handler func (* Context )
107
+ type Handler = func (* Context )
108
108
109
109
// Handlers is just a type of slice of []Handler.
110
110
//
111
111
// See `Handler` for more.
112
- type Handlers []Handler
112
+ type Handlers = []Handler
113
113
114
114
func valueOf (v interface {}) reflect.Value {
115
115
if val , ok := v .(reflect.Value ); ok {
Original file line number Diff line number Diff line change 1
1
package iris
2
2
3
+ import (
4
+ "github.com/kataras/iris/v12/context"
5
+ )
6
+
3
7
// ContextPool is a pool of T.
4
8
//
5
9
// See `NewContextWrapper` and `ContextPool` for more.
@@ -76,16 +80,35 @@ func NewContextWrapper[T any](pool ContextPool[T]) *ContextWrapper[T] {
76
80
}
77
81
}
78
82
83
+ // Pool returns the pool, useful when manually Acquire and Release of custom context is required.
84
+ func (w * ContextWrapper [T ]) Pool () ContextPool [T ] {
85
+ return w .pool
86
+ }
87
+
79
88
// Handler wraps the handler with the pool's Acquire and Release methods.
80
89
// It returns a new handler which expects a T instead of iris.Context.
81
90
// The T is the type of the pool.
82
91
// The T is acquired from the pool and released back to the pool after the handler's execution.
83
92
// The T is passed to the handler as an argument.
84
93
// The T is not shared between requests.
85
94
func (w * ContextWrapper [T ]) Handler (handler func (T )) Handler {
95
+ if handler == nil {
96
+ return nil
97
+ }
98
+
86
99
return func (ctx Context ) {
87
100
newT := w .pool .Acquire (ctx )
88
101
handler (newT )
89
102
w .pool .Release (newT )
90
103
}
91
104
}
105
+
106
+ // Handlers wraps the handlers with the pool's Acquire and Release methods.
107
+ func (w * ContextWrapper [T ]) Handlers (handlers ... func (T )) context.Handlers {
108
+ newHandlers := make (context.Handlers , len (handlers ))
109
+ for i , handler := range handlers {
110
+ newHandlers [i ] = w .Handler (handler )
111
+ }
112
+
113
+ return newHandlers
114
+ }
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ func FromStd(handler interface{}) context.Handler {
18
18
switch h := handler .(type ) {
19
19
case context.Handler :
20
20
return h
21
- case func (* context.Context ):
22
- return h
21
+ // case func(*context.Context):
22
+ // return h
23
23
case http.Handler :
24
24
// handlerFunc.ServeHTTP(w,r)
25
25
return func (ctx * context.Context ) {
Original file line number Diff line number Diff line change @@ -1388,7 +1388,7 @@ func (api *APIBuilder) RemoveHandler(namesOrHandlers ...interface{}) Party {
1388
1388
switch h := nameOrHandler .(type ) {
1389
1389
case string :
1390
1390
handlerName = h
1391
- case context.Handler , func (* context.Context ):
1391
+ case context.Handler : // , func(*context.Context):
1392
1392
handlerName = context .HandlerName (h )
1393
1393
case * int :
1394
1394
counter = h
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ func (r *Route) RemoveHandler(namesOrHandlers ...interface{}) (count int) {
160
160
switch h := nameOrHandler .(type ) {
161
161
case string :
162
162
handlerName = h
163
- case context.Handler , func (* context.Context ):
163
+ case context.Handler : // , func(*context.Context):
164
164
handlerName = context .HandlerName (h )
165
165
default :
166
166
panic (fmt .Sprintf ("remove handler: unexpected type of %T" , h ))
You can’t perform that action at this time.
0 commit comments