summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-07-26 14:04:01 +0800
committerGitHub <noreply@github.com>2023-07-26 06:04:01 +0000
commitdcd3a631288686a95cedbd4aa9cce245e896825d (patch)
treee8c726ec07c3cb54fc092d63d2713fee409ee7b4 /modules/context
parent338d03ce2f05fcc49a577b58a6cfa6beb7996fd1 (diff)
downloadgitea-dcd3a631288686a95cedbd4aa9cce245e896825d.tar.gz
gitea-dcd3a631288686a95cedbd4aa9cce245e896825d.zip
Move web JSON functions to web context and simplify code (#26132)
The JSONRedirect/JSONOK/JSONError functions were put into "Base" context incorrectly, it would cause abuse. Actually, they are for "web context" only, so, move them to the correct place. And by the way, use them to simplify old code: +75 -196
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/base.go12
-rw-r--r--modules/context/context.go12
2 files changed, 12 insertions, 12 deletions
diff --git a/modules/context/base.go b/modules/context/base.go
index 8566ef7861..83e5a214f8 100644
--- a/modules/context/base.go
+++ b/modules/context/base.go
@@ -136,18 +136,6 @@ func (b *Base) JSON(status int, content any) {
}
}
-func (b *Base) JSONRedirect(redirect string) {
- b.JSON(http.StatusOK, map[string]any{"redirect": redirect})
-}
-
-func (b *Base) JSONOK() {
- b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
-}
-
-func (b *Base) JSONError(msg string) {
- b.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg})
-}
-
// RemoteAddr returns the client machine ip address
func (b *Base) RemoteAddr() string {
return b.Req.RemoteAddr
diff --git a/modules/context/context.go b/modules/context/context.go
index 47a04c989c..de0518a1d2 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -226,3 +226,15 @@ func (ctx *Context) GetErrMsg() string {
}
return msg
}
+
+func (ctx *Context) JSONRedirect(redirect string) {
+ ctx.JSON(http.StatusOK, map[string]any{"redirect": redirect})
+}
+
+func (ctx *Context) JSONOK() {
+ ctx.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
+}
+
+func (ctx *Context) JSONError(msg string) {
+ ctx.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg})
+}