Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d21d05

Browse files
authored
Merge pull request studygolang#80 from 15ho/master
bugfix:middleware.NeedLogin()
2 parents 35d786c + 035dead commit 8d21d05

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/http/middleware/login.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func NeedLogin() echo.MiddlewareFunc {
7676
method := ctx.Request().Method()
7777
if util.IsAjax(ctx) {
7878
if !strings.HasPrefix(ctx.Path(), "/account") {
79-
return ctx.JSON(http.StatusForbidden, `{"ok":0,"error":"403 Forbidden"}`)
79+
return ctx.JSON(http.StatusForbidden, map[string]interface{}{"ok": 0, "error": "403 Forbidden"})
8080
}
8181
} else {
8282
if method == "POST" {
@@ -137,6 +137,5 @@ func AppNeedLogin() echo.MiddlewareFunc {
137137

138138
func outputAppJSON(ctx echo.Context, code int, msg string) error {
139139
AccessControl(ctx)
140-
respJSON := `{"code":` + strconv.Itoa(code) + `,"msg":"` + msg + `}`
141-
return ctx.JSON(http.StatusForbidden, respJSON)
140+
return ctx.JSON(http.StatusForbidden, map[string]interface{}{"code": strconv.Itoa(code), "msg": msg})
142141
}

0 commit comments

Comments
 (0)