Skip to content

Commit

Permalink
update: cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky committed Jul 13, 2024
1 parent 04c18c9 commit 26c9f22
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion internal/service/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Login(c *gin.Context) {
// 注册之后的下次登录成功,才会为其生成 token
token := jwt.GenerateToken(user)
// 打印相应信息和用户信息以及生成的 token 值
util.OKWithData(c, false, LoginResponse{
util.OKWithData(c, LoginResponse{
Token: token,
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ProfileMe(c *gin.Context) {
roles = []string{}
}

util.OKWithData(c, true, ProfileMeResponse{
util.OKWithData(c, ProfileMeResponse{
Avatar: user.Avatar,
Background: user.Background,
CreatedAt: user.CreatedAt.Format("2006-01-02 15:04:05"),
Expand Down
2 changes: 1 addition & 1 deletion internal/service/user/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Register(c *gin.Context) {
return
}

util.OKWithData(c, false, RegisterDataResponse{
util.OKWithData(c, RegisterDataResponse{
Email: user.Email,
UserID: strconv.FormatInt(int64(user.UserID), 10),
Username: user.Username,
Expand Down
26 changes: 1 addition & 25 deletions module/util/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"strconv"

"github.com/TensoRaws/NuxBT-Backend/module/log"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -40,35 +39,12 @@ func AbortWithMsg(c *gin.Context, msg string) {
}

// OKWithData 返回成功信息,携带自定义数据(结构体)
func OKWithData(c *gin.Context, cache bool, data interface{}) {
func OKWithData(c *gin.Context, data interface{}) {
resp := map[string]interface{}{
"success": true,
"message": "ok",
"data": data,
}
if cache {
c.Set("cache",
StructToString(
map[string]interface{}{
"success": true,
"message": "cache",
"data": data,
},
),
)
}

c.JSON(http.StatusOK, resp)
}

// OKWithCache 返回缓存数据,终止请求
func OKWithCache(c *gin.Context, cache string) {
var resp interface{}
err := StringToStruct(cache, &resp)
if err != nil {
log.Logger.Error(err)
return
}
c.JSON(http.StatusOK, resp)
c.Abort()
}

0 comments on commit 26c9f22

Please sign in to comment.