From a70efc820351eea33569c52e57f3a476421df8dd Mon Sep 17 00:00:00 2001 From: ZGGSONG Date: Tue, 10 May 2022 10:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BF=A1=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E4=B8=80=E5=B1=82user=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/info.go | 4 +++- dto/user_dto.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 dto/user_dto.go 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, + } +}