Skip to content

Commit

Permalink
Version 0.3.15
Browse files Browse the repository at this point in the history
* 重要更新: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
  • Loading branch information
[email protected] committed May 20, 2017
1 parent 4f5e818 commit 4211f40
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ dotweb.json.conf
11、Router.RegisterRoute(routeMethod string, path string, handle HttpHandle)
12、Router.RegisterHandler(name string, handler HttpHandle)
13、Router.GetHandler(name string) (HttpHandle, bool)
14、Router.MatchPath(ctx *HttpContext, routePath string) bool
14、Router.MatchPath(ctx Context, routePath string) bool
```
接受两个参数,一个是URI路径,另一个是 HttpHandle 类型,设定匹配到该路径时执行的方法;
#### 2) 静态路由
Expand Down Expand Up @@ -294,7 +294,7 @@ func NewAccessFmtLog(index string) *AccessFmtLog {
* 默认设置: 当发生未处理异常时,会根据RunMode向页面输出默认错误信息或者具体异常信息,并返回 500 错误头
* 自定义: 通过DotServer.SetExceptionHandle(handler *ExceptionHandle)实现自定义异常处理逻辑
```go
type ExceptionHandle func(*HttpContext, interface{})
type ExceptionHandle func(Context, error)
```

## 9. Session
Expand Down
4 changes: 2 additions & 2 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const (
type (
// Binder is the interface that wraps the Bind method.
Binder interface {
Bind(interface{}, *HttpContext) error
Bind(interface{}, Context) error
}

binder struct{}
)

func (b *binder) Bind(i interface{}, ctx *HttpContext) (err error) {
func (b *binder) Bind(i interface{}, ctx Context) (err error) {
req := ctx.Request()
ctype := req.Header.Get(HeaderContentType)
if req.Body == nil {
Expand Down
2 changes: 1 addition & 1 deletion dotweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type (
NotFoundHandle http.Handler

// Handle is a function that can be registered to a route to handle HTTP
// requests. Like http.HandlerFunc, but has a special parameter *HttpContext contain all request and response data.
// requests. Like http.HandlerFunc, but has a special parameter Context contain all request and response data.
HttpHandle func(Context) error
)

Expand Down
2 changes: 1 addition & 1 deletion feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
}

//set CROS config on HttpContext
func (f *xFeatureTools) SetCROSConfig(ctx *HttpContext, c *feature.CROSConfig) {
func (f *xFeatureTools) SetCROSConfig(ctx Context, c *feature.CROSConfig) {
ctx.Response().SetHeader(HeaderAccessControlAllowOrigin, c.AllowedOrigins)
ctx.Response().SetHeader(HeaderAccessControlAllowMethods, c.AllowedMethods)
ctx.Response().SetHeader(HeaderAccessControlAllowHeaders, c.AllowedHeaders)
Expand Down
4 changes: 2 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type Renderer interface {
//模板查找顺序从最后一个插入的元素开始往前找
//默认添加base、base/templates、base/views
SetTemplatePath(path ...string)
Render(io.Writer, string, interface{}, *HttpContext) error
Render(io.Writer, string, interface{}, Context) error
}

type innerRenderer struct {
templatePaths []string
}

// Render render view use http/template
func (r *innerRenderer) Render(w io.Writer, tpl string, data interface{}, ctx *HttpContext) error {
func (r *innerRenderer) Render(w io.Writer, tpl string, data interface{}, ctx Context) error {
t, err := r.parseFile(tpl)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (server *HttpServer) SetEnabledGzip(isEnabled bool) {
}

//do features...
func (server *HttpServer) doFeatures(ctx *HttpContext) *HttpContext {
func (server *HttpServer) doFeatures(ctx Context) Context {
//处理 cros feature
if server.Features.CROSConfig != nil {
c := server.Features.CROSConfig
Expand Down Expand Up @@ -328,7 +328,7 @@ func (server *HttpServer) wrapRouterHandle(handler HttpHandle, isHijack bool) Ro
}()

//do features
httpCtx = server.doFeatures(httpCtx)
server.doFeatures(httpCtx)

//处理前置Module集合
for _, module := range server.DotApp.Modules {
Expand Down

0 comments on commit 4211f40

Please sign in to comment.