框架基本搭建完成

This commit is contained in:
2022-04-03 12:30:50 +08:00
commit ec4c957b25
31 changed files with 1353 additions and 0 deletions

59
pkg/dto/response.go Normal file
View File

@@ -0,0 +1,59 @@
package dto
import (
"drive-linked/pkg/serializer"
"github.com/kataras/iris/v12"
"net/http"
)
type Response struct {
Ctx iris.Context
}
func NewResponse(ctx iris.Context) *Response {
return &Response{Ctx: ctx}
}
const errJsonUnmarshalMsg = "{\"code\":500,\"msg\":\"Json解析错误请联系管理员\",\"data\":null}"
// 成功 统一处理
func (r *Response) Success(data interface{}) {
res := serializer.Response{
Code: 200,
Msg: "",
Data: data,
}
_, err := r.Ctx.JSON(res)
if err != nil {
r.Ctx.Write([]byte(errJsonUnmarshalMsg))
return
}
}
// 失败 统一处理
func (r *Response) Error(code int32, msg string) {
res := serializer.Response{
Code: code,
Msg: msg,
Data: nil,
}
_, err := r.Ctx.JSON(res)
if err != nil {
r.Ctx.Write([]byte(errJsonUnmarshalMsg))
return
}
}
// 参数类型错误
func (r *Response) ErrInvalidParamType() (err error) {
res := serializer.Response{
Code: http.StatusBadRequest,
Msg: "参数类型错误",
Data: nil,
}
_, err = r.Ctx.JSON(res)
if err != nil {
return err
}
return nil
}

29
pkg/dto/user.go Normal file
View File

@@ -0,0 +1,29 @@
package dto
import (
"drive-linked/pkg/model"
"github.com/jinzhu/copier"
)
type UserProfile struct {
Id int64 `json:"id,string"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Email string `json:"email"`
Status int32 `json:"status"`
Avatar string `json:"avatar"`
Roles string `json:"roles"`
}
type QueryUser struct {
Method string `json:"method"`
Value string `json:"value"`
}
func (u *UserProfile) CopyOf(user *model.User) error {
err := copier.Copy(u, user)
if err != nil {
return err
}
return nil
}