diff options
author | Unknwon <u@gogs.io> | 2015-02-22 09:49:25 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-02-22 09:49:25 -0500 |
commit | 059338139ca4a70cb1138dc09039abb5dac0d0f2 (patch) | |
tree | 4b80829314df3b9f7e21b67ccf5fc30146f0c4e4 /modules/middleware/context.go | |
parent | c753fdceaf0549aa865cff4e1f42be5d907bbdb1 (diff) | |
download | gitea-059338139ca4a70cb1138dc09039abb5dac0d0f2.tar.gz gitea-059338139ca4a70cb1138dc09039abb5dac0d0f2.zip |
routers: able to migrate repo from local path
- modules/middleware/context.go: add HandleAPI method
Diffstat (limited to 'modules/middleware/context.go')
-rw-r--r-- | modules/middleware/context.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 28be3a3025..45779d5800 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -130,6 +130,18 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } +func (ctx *Context) HandleAPI(status int, obj interface{}) { + var message string + if err, ok := obj.(error); ok { + message = err.Error() + } else { + message = obj.(string) + } + ctx.JSON(status, map[string]string{ + "message": message, + }) +} + func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) { modtime := time.Now() for _, p := range params { |