-
Notifications
You must be signed in to change notification settings - Fork 10
/
doc.go
212 lines (196 loc) · 6.39 KB
/
doc.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package web
import (
"context"
"net/http"
"net/url"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/mylxsw/go-ioc"
)
type Context interface {
JSON(res interface{}) *JSONResponse
NewJSONResponse(res interface{}) *JSONResponse
YAML(res interface{}) *YAMLResponse
NewYAMLResponse(res interface{}) *YAMLResponse
JSONWithCode(res interface{}, code int) *JSONResponse
Nil() *NilResponse
API(businessCode string, message string, data interface{}) *JSONResponse
NewAPIResponse(businessCode string, message string, data interface{}) *JSONResponse
Raw(func(w http.ResponseWriter)) *RawResponse
NewRawResponse(func(w http.ResponseWriter)) *RawResponse
NewHTMLResponse(res string) *HTMLResponse
HTML(res string) *HTMLResponse
HTMLWithCode(res string, code int) *HTMLResponse
Error(res string, code int) *ErrorResponse
JSONError(res string, code int) *JSONResponse
NewErrorResponse(res string, code int) *ErrorResponse
Redirect(location string, code int) *RedirectResponse
Resolve(callback interface{}) Response
Decode(v interface{}) error
Unmarshal(v interface{}) error
UnmarshalYAML(v interface{}) error
PathVar(key string) string
PathVars() map[string]string
Input(key string) string
JSONGet(keys ...string) string
InputWithDefault(key string, defaultVal string) string
ToInt(val string, defaultVal int) int
ToInt64(val string, defaultVal int64) int64
ToFloat32(val string, defaultVal float32) float32
ToFloat64(val string, defaultVal float64) float64
IntInput(key string, defaultVal int) int
Int64Input(key string, defaultVal int64) int64
Float32Input(key string, defaultVal float32) float32
Float64Input(key string, defaultVal float64) float64
File(key string) (*UploadedFile, error)
IsXMLHTTPRequest() bool
AJAX() bool
IsJSON() bool
ContentType() string
AllHeaders() http.Header
Headers(key string) []string
Header(key string) string
Is(method string) bool
IsGet() bool
IsPost() bool
IsHead() bool
IsDelete() bool
IsPut() bool
IsPatch() bool
IsOptions() bool
Method() string
Body() []byte
Set(key string, value interface{})
Get(key string) interface{}
Context() context.Context
Cookie(name string) (*http.Cookie, error)
Cookies() []*http.Cookie
Session() *sessions.Session
Request() Request
Response() ResponseCreator
Container() ioc.Container
View(tplPath string, data interface{}) *HTMLResponse
Validate(validator Validator, jsonResponse bool)
RemoteAddr() string
RouteURL(name string, pairs ...string) (*url.URL, error)
RouteByName(name string) RouteAware
CurrentRoute() RouteAware
}
type Request interface {
Raw() *http.Request
Decode(v interface{}) error
Unmarshal(v interface{}) error
UnmarshalYAML(v interface{}) error
PathVar(key string) string
PathVars() map[string]string
Input(key string) string
JSONGet(keys ...string) string
InputWithDefault(key string, defaultVal string) string
ToInt(val string, defaultVal int) int
ToInt64(val string, defaultVal int64) int64
ToFloat32(val string, defaultVal float32) float32
ToFloat64(val string, defaultVal float64) float64
IntInput(key string, defaultVal int) int
Int64Input(key string, defaultVal int64) int64
Float32Input(key string, defaultVal float32) float32
Float64Input(key string, defaultVal float64) float64
File(key string) (*UploadedFile, error)
IsXMLHTTPRequest() bool
AJAX() bool
IsJSON() bool
ContentType() string
AllHeaders() http.Header
Headers(key string) []string
Header(key string) string
Is(method string) bool
IsGet() bool
IsPost() bool
IsHead() bool
IsDelete() bool
IsPut() bool
IsPatch() bool
IsOptions() bool
Method() string
Body() []byte
Set(key string, value interface{})
Get(key string) interface{}
Context() context.Context
Cookie(name string) (*http.Cookie, error)
Cookies() []*http.Cookie
Session() *sessions.Session
SetSession(session *sessions.Session)
RouteURL(name string, pairs ...string) (*url.URL, error)
RouteByName(name string) RouteAware
CurrentRoute() RouteAware
Validate(validator Validator, jsonResponse bool)
RemoteAddr() string
}
// Response is the response interface
type Response interface {
CreateResponse() error
Code() int
}
// Controller is a interface for controller
type Controller interface {
// Register register routes for a controller
Register(router Router)
}
// ResponseCreator is a response creator
type ResponseCreator interface {
Raw() http.ResponseWriter
SetCode(code int)
ResponseWriter() http.ResponseWriter
SetContent(content []byte)
Header(key, value string)
Cookie(cookie *http.Cookie)
GetCode() int
Flush()
}
type Router interface {
Group(prefix string, f func(router Router), decors ...HandlerDecorator)
Perform(exceptionHandler ExceptionHandler, cb func(*mux.Router)) http.Handler
GetRoutes() []RouteRule
Any(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Get(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Post(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Delete(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Put(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Patch(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Head(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Options(path string, handler interface{}, middlewares ...HandlerDecorator) RouteRule
Controllers(prefix string, controllers ...Controller)
WithMiddleware(decors ...HandlerDecorator) *MiddlewareRouter
}
type RouteRule interface {
Custom(custom func(rou *mux.Route)) RouteRule
Name(name string) RouteRule
Headers(pairs ...string) RouteRule
Queries(pairs ...string) RouteRule
Schemes(schemes ...string) RouteRule
Host(tpl string) RouteRule
Path(path string) RouteRule
Decorators(dec ...HandlerDecorator) RouteRule
GetName() string
GetHost() string
GetQueries() []string
GetSchemas() []string
GetHeaders() []string
GetCustom() func(rou *mux.Route)
GetDecorators() []HandlerDecorator
GetWebHandler() WebHandler
GetPath() string
GetMethod() string
}
type RouteAware interface {
SkipClean() bool
GetName() string
URL(pairs ...string) (*url.URL, error)
URLHost(pairs ...string) (*url.URL, error)
URLPath(pairs ...string) (*url.URL, error)
GetPathTemplate() (string, error)
GetPathRegexp() (string, error)
GetQueriesRegexp() ([]string, error)
GetQueriesTemplates() ([]string, error)
GetMethods() ([]string, error)
GetHostTemplate() (string, error)
}