获取信息时转换一层user信息进行保护

master
ZGGSONG 3 years ago
parent c757f282db
commit a70efc8203

@ -4,6 +4,8 @@ import (
"net/http" "net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/zggsong/gin-vue-demo/dto"
"github.com/zggsong/gin-vue-demo/model"
) )
func Info(ctx *gin.Context) { func Info(ctx *gin.Context) {
@ -11,6 +13,6 @@ func Info(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{ ctx.JSON(http.StatusOK, gin.H{
"code": http.StatusOK, "code": http.StatusOK,
"data": gin.H{"user": user}, "data": gin.H{"user": dto.ToUserDto(user.(model.User))},
}) })
} }

@ -0,0 +1,15 @@
package dto
import "github.com/zggsong/gin-vue-demo/model"
type UserDto struct {
Name string `json:"name"`
Telephone string `json:"telephone"`
}
func ToUserDto(user model.User) UserDto {
return UserDto{
Name: user.Name,
Telephone: user.Telephone,
}
}
Loading…
Cancel
Save