-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexecution.go
56 lines (47 loc) · 991 Bytes
/
execution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package powermux
import (
"net/http"
"sync"
)
// routeExecution is the complete instructions for running serve on a route
type routeExecution struct {
pattern string
params map[string]string
notFound http.Handler
middleware []Middleware
handler http.Handler
}
func newExecution() *routeExecution {
return &routeExecution{
middleware: make([]Middleware, 0),
params: make(map[string]string),
}
}
func (ex *routeExecution) Reset() {
ex.middleware = ex.middleware[0:0]
for key := range ex.params {
delete(ex.params, key)
}
ex.handler = nil
ex.notFound = nil
}
type executionPool struct {
p *sync.Pool
}
func (ep *executionPool) Get() *routeExecution {
return ep.p.Get().(*routeExecution)
}
func (ep *executionPool) Put(ex *routeExecution) {
ex.Reset()
ep.p.Put(ex)
}
func createExecution() interface{} {
return newExecution()
}
func newExecutionPool() *executionPool {
return &executionPool{
p: &sync.Pool{
New: createExecution,
},
}
}