Skip to content

Commit

Permalink
update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 11, 2020
1 parent c2bc88e commit e5d2cc7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions context_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func (c *Context) Respond(status int, obj interface{}, renderer render.Renderer)

err := renderer.Render(c.Resp, obj)
if err != nil {
panic(err) // TODO or use AddError()
// panic(err) // TODO or use AddError()
c.AddError(err)
}
}

Expand Down Expand Up @@ -96,7 +97,9 @@ func (c *Context) Stream(status int, contentType string, r io.Reader) {
_, err := io.Copy(c.Resp, r)

if err != nil {
panic(err)
// TODO use AddError()
// panic(err)
c.AddError(err)
}
}

Expand Down
6 changes: 4 additions & 2 deletions extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type Validator interface {
* Context function extends()
*************************************************************/

// Render context template
// Render context template.
//
// please use ShouldRender() instead
func (c *Context) Render(status int, name string, data interface{}) (err error) {
if c.router.Renderer == nil {
return errors.New("renderer not registered")
Expand All @@ -43,7 +45,7 @@ func (c *Context) Render(status int, name string, data interface{}) (err error)

// Validate context validator
// Deprecated
// please use ShouldBind(), it will auto call validator.
// please use ShouldBind() instead, it will auto call validator.
func (c *Context) Validate(i interface{}) error {
if c.Router().Validator == nil {
return errors.New("validator not registered")
Expand Down
6 changes: 1 addition & 5 deletions render/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ func (r JSONRenderer) Render(w http.ResponseWriter, obj interface{}) (err error)
enc.SetEscapeHTML(false)
}

if err = enc.Encode(obj); err != nil {
return err
}

return err
return enc.Encode(obj)
}

// JSON response rendering
Expand Down
2 changes: 2 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ type Router struct {
// Extends tools
//
// Renderer template(view) interface
// Deprecated
Renderer Renderer
// Validator validator interface
// Deprecated
Validator Validator
}

Expand Down

0 comments on commit e5d2cc7

Please sign in to comment.