forked from gramework/gramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
143 lines (117 loc) · 2.97 KB
/
types.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package gramework
import (
"sync"
"github.com/apex/log"
"github.com/gramework/utils/nocopy"
"github.com/valyala/fasthttp"
)
type (
// App represents a gramework app
App struct {
name string
defaultRouter *Router
errorHandler func(func(*fasthttp.RequestCtx) error)
EnableFirewall bool
firewall *firewall
firewallInit *sync.Once
Logger log.Interface
TLSEmails []string
Settings Settings
HandleUnknownDomains bool
domains map[string]*Router
Flags *Flags
flagsRegistered bool
flagsQueue []Flag
domainListLock *sync.RWMutex
preMiddlewares []func(*Context)
middlewares []func(*Context)
middlewaresAfterRequest []func(*Context)
middlewaresMu *sync.RWMutex
preMiddlewaresMu *sync.RWMutex
middlewaresAfterRequestMu *sync.RWMutex
}
// Context is a gramework request context
Context struct {
*fasthttp.RequestCtx
nocopy nocopy.NoCopy
Logger log.Interface
App *App
auth *Auth
Cookies Cookies
middlewaresShouldStopProcessing bool
}
// Cookies handles a typical cookie storage
Cookies struct {
Storage map[string]string
Mu sync.RWMutex
}
// Settings for an App instance
Settings struct {
Firewall FirewallSettings
}
// FirewallSettings represents a new firewall settings.
// Internal firewall representation copies this settings
// atomically.
FirewallSettings struct {
// MaxReqPerMin is a max request per minute count
MaxReqPerMin int64
// BlockTimeout in seconds
BlockTimeout int64
}
firewall struct {
// Store a copy of current settings
MaxReqPerMin *int64
BlockTimeout *int64
blockList map[string]int64
blockListMutex sync.Mutex
requestCounter map[string]int64
requestCounterMutex sync.Mutex
}
// Flags is a flags storage
Flags struct {
values map[string]Flag
}
// Flag is a flag representation
Flag struct {
Name string
Description string
Value *string
Default string
}
// Router handles internal handler conversion etc.
Router struct {
router *router
httprouter *Router
httpsrouter *Router
root *Router
app *App
mu sync.RWMutex
submu sync.Mutex
}
// SubRouter handles subs registration
// like app.Sub("v1").GET("someRoute", "hi")
SubRouter struct {
parent routerable
prefix string
}
routerable interface {
handleReg(method, route string, handler interface{})
determineHandler(handler interface{}) func(*Context)
}
// RequestHandler describes a standard request handler type
RequestHandler func(*Context)
// RequestHandlerErr describes a standard request handler with error returned type
RequestHandlerErr func(*Context) error
// Auth is a struct that handles
// context's basic auth features
Auth struct {
login string
pass string
parsed bool
// if error occurred during parsing,
// it will be always returned for current
// context
err error
ctx *Context
}
)