diff --git a/controller/info.go b/controller/info.go index fe1d50d..13e92ee 100644 --- a/controller/info.go +++ b/controller/info.go @@ -4,6 +4,8 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/zggsong/gin-vue-demo/dto" + "github.com/zggsong/gin-vue-demo/model" ) func Info(ctx *gin.Context) { @@ -11,6 +13,6 @@ func Info(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{ "code": http.StatusOK, - "data": gin.H{"user": user}, + "data": gin.H{"user": dto.ToUserDto(user.(model.User))}, }) } diff --git a/dto/user_dto.go b/dto/user_dto.go new file mode 100644 index 0000000..7c21e51 --- /dev/null +++ b/dto/user_dto.go @@ -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, + } +}