@@ -23,7 +23,7 @@ go get github.com/devfeel/dotweb
23
23
```
24
24
25
25
## 2. Getting Started
26
- ``` go
26
+ ``` go
27
27
package main
28
28
29
29
import (
@@ -58,6 +58,7 @@ func main() {
58
58
* Feature支持,可绑定HttpServer全局启用
59
59
* 支持STRING/JSON/JSONP/HTML格式输出
60
60
* 集成Mock能力
61
+ * 支持自定义Context
61
62
* 集成Timeout Hook
62
63
* 全局HTTP错误处理
63
64
* 全局日志处理
@@ -103,26 +104,26 @@ cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min |
103
104
* 支持通过配置开启默认添加HEAD方式
104
105
* 支持注册Handler,以启用配置化
105
106
* 支持检查请求与指定路由是否匹配
106
- ``` go
107
- 1 、 Router.GET (path string , handle HttpHandle )
108
- 2 、 Router.POST (path string , handle HttpHandle )
109
- 3 、 Router.HEAD (path string , handle HttpHandle )
110
- 4 、 Router.OPTIONS (path string , handle HttpHandle )
111
- 5 、 Router.PUT (path string , handle HttpHandle )
112
- 6 、 Router.PATCH (path string , handle HttpHandle )
113
- 7 、 Router.DELETE (path string , handle HttpHandle )
114
- 8 、 Router.HiJack (path string , handle HttpHandle )
115
- 9 、 Router.WebSocket (path string , handle HttpHandle )
116
- 10 、 Router.Any (path string , handle HttpHandle )
117
- 11 、 Router.RegisterRoute (routeMethod string , path string , handle HttpHandle )
118
- 12 、 Router.RegisterHandler (name string , handler HttpHandle )
119
- 13 、 Router.GetHandler (name string ) (HttpHandle, bool )
120
- 14 、 Router.MatchPath (ctx Context , routePath string ) bool
107
+ ``` go
108
+ Router.GET (path string , handle HttpHandle )
109
+ Router.POST (path string , handle HttpHandle )
110
+ Router.HEAD (path string , handle HttpHandle )
111
+ Router.OPTIONS (path string , handle HttpHandle )
112
+ Router.PUT (path string , handle HttpHandle )
113
+ Router.PATCH (path string , handle HttpHandle )
114
+ Router.DELETE (path string , handle HttpHandle )
115
+ Router.HiJack (path string , handle HttpHandle )
116
+ Router.WebSocket (path string , handle HttpHandle )
117
+ Router.Any (path string , handle HttpHandle )
118
+ Router.RegisterRoute (routeMethod string , path string , handle HttpHandle )
119
+ Router.RegisterHandler (name string , handler HttpHandle )
120
+ Router.GetHandler (name string ) (HttpHandle, bool )
121
+ Router.MatchPath (ctx Context , routePath string ) bool
121
122
```
122
123
接受两个参数,一个是URI路径,另一个是 HttpHandle 类型,设定匹配到该路径时执行的方法;
123
124
#### 2) static router
124
125
静态路由语法就是没有任何参数变量,pattern是一个固定的字符串。
125
- ``` go
126
+ ``` go
126
127
package main
127
128
128
129
import (
@@ -141,7 +142,7 @@ test:
141
142
curl http://127.0.0.1/hello
142
143
#### 3) parameter router
143
144
参数路由以冒号 : 后面跟一个字符串作为参数名称,可以通过 HttpContext的 GetRouterName 方法获取路由参数的值。
144
- ``` go
145
+ ``` go
145
146
package main
146
147
147
148
import (
@@ -165,7 +166,7 @@ test:
165
166
<br >curl http://127.0.0.1/hello/devfeel
166
167
<br >curl http://127.0.0.1/hello/category1/1
167
168
#### 4) group router
168
- ``` go
169
+ ``` go
169
170
g := server.Group (" /user" )
170
171
g.GET (" /" , Index )
171
172
g.GET (" /profile" , Profile )
@@ -178,7 +179,7 @@ test:
178
179
## 6. Binder
179
180
* HttpContext.Bind(interface{})
180
181
* Support data from json、xml、Form
181
- ``` go
182
+ ``` go
182
183
type UserInfo struct {
183
184
UserName string ` form:"user"`
184
185
Sex int ` form:"sex"`
@@ -213,7 +214,7 @@ func TestBind(ctx dotweb.HttpContext) error{
213
214
* Recover
214
215
* HeaderOverride
215
216
216
- ``` go
217
+ ``` go
217
218
app.Use (NewAccessFmtLog (" app" ))
218
219
219
220
func InitRoute (server *dotweb .HttpServer ) {
@@ -286,13 +287,13 @@ func NewAccessFmtLog(index string) *AccessFmtLog {
286
287
#### 500 error
287
288
* Default: 当发生未处理异常时,会根据RunMode向页面输出默认错误信息或者具体异常信息,并返回 500 错误头
288
289
* User-defined: 通过DotServer.SetExceptionHandle(handler * ExceptionHandle)实现自定义异常处理逻辑
289
- ``` go
290
+ ``` go
290
291
type ExceptionHandle func (Context, error )
291
292
```
292
293
#### 404 error
293
294
* Default: 当发生404异常时,会默认使用http.NotFound处理
294
295
* User-defined: 通过DotWeb.SetNotFoundHandle(handler NotFoundHandle)实现自定义404处理逻辑
295
- ``` go
296
+ ``` go
296
297
type NotFoundHandle func (http.ResponseWriter , *http.Request )
297
298
```
298
299
0 commit comments