diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-15 09:17:16 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-15 09:17:16 -0400 |
commit | f174633b36ef102d8e8324dd708b96335188f5dd (patch) | |
tree | d173c5dfa791ff9b107b426b8445d9b552a854b1 /modules/middleware | |
parent | b3919c577f7082bad3955e039691c83b63c241e9 (diff) |
Clean code
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/context.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 31678237..dccd3351 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -5,6 +5,7 @@ package middleware import ( + "fmt" "net/http" "github.com/codegangsta/martini" @@ -17,6 +18,7 @@ import ( "github.com/gogits/gogs/modules/log" ) +// Context represents context of a request. type Context struct { c martini.Context p martini.Params @@ -29,6 +31,7 @@ type Context struct { IsSigned bool } +// Query querys form parameter. func (ctx *Context) Query(name string) string { ctx.Req.ParseForm() return ctx.Req.Form.Get(name) @@ -38,10 +41,14 @@ func (ctx *Context) Query(name string) string { // return ctx.p[name] // } -func (ctx *Context) Log(status int, title string, err error) { - log.Handle(status, title, ctx.Data, ctx.Render, err) +// Handle handles and logs error by given status. +func (ctx *Context) Handle(status int, title string, err error) { + ctx.Data["ErrorMsg"] = err + log.Error("%s: %v", title, err) + ctx.Render.HTML(status, fmt.Sprintf("status/%d", status), ctx.Data) } +// InitContext initializes a classic context for a request. func InitContext() martini.Handler { return func(res http.ResponseWriter, r *http.Request, c martini.Context, session sessions.Session, rd render.Render) { |