Use c.ResponseError() for all places.

This commit is contained in:
Yang Luo
2021-08-08 11:06:45 +08:00
parent 6aeadfa3bd
commit d16569d461
5 changed files with 24 additions and 66 deletions

View File

@ -69,19 +69,11 @@ func (c *ApiController) ResponseError(error string, data ...interface{}) {
c.ServeJSON()
}
// ResponseErrorWithData ...
func (c *ApiController) ResponseErrorWithData(error string, data interface{}) {
c.Data["json"] = Response{Status: "error", Msg: error, Data: data}
c.ServeJSON()
}
// RequireSignedIn ...
func (c *ApiController) RequireSignedIn() (string, bool) {
userId := c.GetSessionUsername()
if userId == "" {
resp := Response{Status: "error", Msg: "Please sign in first"}
c.Data["json"] = resp
c.ServeJSON()
c.ResponseError("Please sign in first")
return "", false
}
return userId, true