@@ -23,7 +23,7 @@ go get github.com/devfeel/dotweb
2323```
2424
2525## 2. Getting Started
26- ``` go
26+ ``` go
2727package main
2828
2929import (
@@ -58,6 +58,7 @@ func main() {
5858* Feature支持,可绑定HttpServer全局启用
5959* 支持STRING/JSON/JSONP/HTML格式输出
6060* 集成Mock能力
61+ * 支持自定义Context
6162* 集成Timeout Hook
6263* 全局HTTP错误处理
6364* 全局日志处理
@@ -103,26 +104,26 @@ cpu | 内存 | Samples | Average | Median | 90%Line | 95%Line | 99%Line | Min |
103104* 支持通过配置开启默认添加HEAD方式
104105* 支持注册Handler,以启用配置化
105106* 支持检查请求与指定路由是否匹配
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
121122```
122123接受两个参数,一个是URI路径,另一个是 HttpHandle 类型,设定匹配到该路径时执行的方法;
123124#### 2) static router
124125静态路由语法就是没有任何参数变量,pattern是一个固定的字符串。
125- ``` go
126+ ``` go
126127package main
127128
128129import (
@@ -141,7 +142,7 @@ test:
141142curl http://127.0.0.1/hello
142143#### 3) parameter router
143144参数路由以冒号 : 后面跟一个字符串作为参数名称,可以通过 HttpContext的 GetRouterName 方法获取路由参数的值。
144- ``` go
145+ ``` go
145146package main
146147
147148import (
@@ -165,7 +166,7 @@ test:
165166<br >curl http://127.0.0.1/hello/devfeel
166167<br >curl http://127.0.0.1/hello/category1/1
167168#### 4) group router
168- ``` go
169+ ``` go
169170 g := server.Group (" /user" )
170171 g.GET (" /" , Index )
171172 g.GET (" /profile" , Profile )
@@ -178,7 +179,7 @@ test:
178179## 6. Binder
179180* HttpContext.Bind(interface{})
180181* Support data from json、xml、Form
181- ``` go
182+ ``` go
182183type UserInfo struct {
183184 UserName string ` form:"user"`
184185 Sex int ` form:"sex"`
@@ -213,7 +214,7 @@ func TestBind(ctx dotweb.HttpContext) error{
213214* Recover
214215* HeaderOverride
215216
216- ``` go
217+ ``` go
217218app.Use (NewAccessFmtLog (" app" ))
218219
219220func InitRoute (server *dotweb .HttpServer ) {
@@ -286,13 +287,13 @@ func NewAccessFmtLog(index string) *AccessFmtLog {
286287#### 500 error
287288* Default: 当发生未处理异常时,会根据RunMode向页面输出默认错误信息或者具体异常信息,并返回 500 错误头
288289* User-defined: 通过DotServer.SetExceptionHandle(handler * ExceptionHandle)实现自定义异常处理逻辑
289- ``` go
290+ ``` go
290291type ExceptionHandle func (Context, error )
291292```
292293#### 404 error
293294* Default: 当发生404异常时,会默认使用http.NotFound处理
294295* User-defined: 通过DotWeb.SetNotFoundHandle(handler NotFoundHandle)实现自定义404处理逻辑
295- ``` go
296+ ``` go
296297type NotFoundHandle func (http.ResponseWriter , *http.Request )
297298```
298299
0 commit comments