Skip to content

Commit ca9f22b

Browse files
author
pzrr@qq.com
committed
Version 0.3.15
* 重要更新:HttpHandle增加error返回值,有error再也不用panic啦! * 重要更新:新增Context接口 * ExceptionHandle func(*HttpContext, error) 调整为 ExceptionHandle func(Context, error) * HttpHandle func(*HttpContext) 调整为 HttpHandle func(Context) error * Middleware.Handle(ctx *HttpContext) error调整为Handle(ctx Context) error * Middleware.Next(ctx *HttpContext)调整为Next(ctx Context) * 为使Context设计与理解更清晰,做以下重要变更: * 迁移Context.QueryStrings()至Context.Request().QueryStrings() * 迁移Context.RawQuery()至Context.Request().RawQuery() * 迁移Context.FormFile()至Context.Request().FormFile() * 迁移Context.FormValues()至Context.Request().FormValues() * 迁移Context.PostBody()至Context.Request().PostBody() * 迁移Context.QueryHeader()至Context.Request().QueryHeader() * 迁移Context.Url()至Context.Request().Url() * 迁移Context.ContentType()至Context.Request().ContentType() * 迁移Context.DelHeader()至Context.Response().DelHeader() * 迁移Context.SetHeader()至Context.Response().SetHeader() * 迁移Context.SetContentType()至Context.Response().SetContentType() * 迁移Context.SetStatusCode()至Context.Response().SetStatusCode() * 废弃Context.PostString(key string) string * 通过在handler内返回相应的error,框架自动命中并通过设置的ExceptionHandle处理 * 更新 example/下所有代码,以支持error返回值,支持Context接口 * 2017-05-20 15:00
1 parent 40ad773 commit ca9f22b

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ type ExceptionHandle func(Context, error)
298298
```
299299
#### 404错误
300300
* 默认设置: 当发生404异常时,会默认使用http.NotFound处理
301-
* 自定义: 通过DotWeb.NotFoundHandler实现自定义404处理逻辑
301+
* 自定义: 通过DotWeb.SetNotFoundHandle(handler NotFoundHandle)实现自定义404处理逻辑
302302
```go
303303
type NotFoundHandle func(http.ResponseWriter, *http.Request)
304304
```

‎dotweb.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func (app *DotWeb) SetExceptionHandle(handler ExceptionHandle) {
155155
app.ExceptionHandler = handler
156156
}
157157

158+
/*
159+
* 设置404处理函数
160+
*/
161+
func (app *DotWeb) SetNotFoundHandle(handler NotFoundHandle) {
162+
app.NotFoundHandler = handler
163+
}
164+
158165
//设置pprofserver启动配置,默认不启动,且该端口号请不要与StartServer的端口号一致
159166
func (app *DotWeb) SetPProfConfig(enabledPProf bool, httpport int) {
160167
app.Config.App.EnabledPProf = enabledPProf

‎example/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ func main() {
4040
InitRoute(app.HttpServer)
4141

4242
//自定义404输出
43-
app.NotFoundHandler = func(w http.ResponseWriter, req *http.Request) {
43+
app.SetNotFoundHandle(func(w http.ResponseWriter, req *http.Request) {
4444
w.WriteHeader(http.StatusNotFound)
4545
w.Write([]byte("is't app's not found!"))
46-
}
46+
})
4747

4848
//设置HttpModule
4949
//InitModule(app)

0 commit comments

Comments
 (0)