diff --git a/.gitignore b/.gitignore index 172736b..3b8f004 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,6 @@ cbuild main output/ manifest/output/ -*.exe \ No newline at end of file +*.exe +tmp/ +resource/log/ \ No newline at end of file diff --git a/apiv1/common/captcha.go b/apiv1/common/captcha.go new file mode 100644 index 0000000..8f781e0 --- /dev/null +++ b/apiv1/common/captcha.go @@ -0,0 +1,19 @@ +/* +* @desc:验证码参数 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 17:47 + */ + +package common + +import "github.com/gogf/gf/v2/frame/g" + +type CaptchaReq struct { + g.Meta `path:"/get" tags:"get captcha" method:"get" summary:"获取验证码"` +} +type CaptchaRes struct { + g.Meta `mime:"application/json" example:"string"` + Key string `json:"key"` + Img string `json:"img"` +} diff --git a/apiv1/demo/demo.go b/apiv1/demo/demo.go new file mode 100644 index 0000000..c39bedf --- /dev/null +++ b/apiv1/demo/demo.go @@ -0,0 +1,18 @@ +/* +* @desc:demo +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 15:25 + */ + +package demo + +import "github.com/gogf/gf/v2/frame/g" + +type DmReq struct { + g.Meta `path:"/demo" tags:"Demo" method:"get" summary:"demo api"` +} +type DmRes struct { + g.Meta `mime:"text/html" example:"string"` + Name string `json:"name"` +} diff --git a/apiv1/system/hello.go b/apiv1/system/hello.go index 847c04c..c91e1f6 100644 --- a/apiv1/system/hello.go +++ b/apiv1/system/hello.go @@ -9,4 +9,5 @@ type HelloReq struct { } type HelloRes struct { g.Meta `mime:"text/html" example:"string"` + Data g.Map `json:"data"` } diff --git a/go.mod b/go.mod index 0eb6bcb..37df702 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,5 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0-rc3 - github.com/tiger1103/gfast-cache v0.0.2 // indirect - github.com/tiger1103/gfast-token v0.0.1 // indirect + github.com/mojocn/base64Captcha v1.3.5 // indirect ) diff --git a/go.sum b/go.sum index 9b16396..f76d05d 100644 --- a/go.sum +++ b/go.sum @@ -20,10 +20,10 @@ github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Px github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/gogf/gf/v2 v2.0.0-rc.0.20220117131058-9345eb5e946f h1:pRSy/LMaK+dDMbzEdsTJwNB7Ms0CUd22soLAUIanbCE= -github.com/gogf/gf/v2 v2.0.0-rc.0.20220117131058-9345eb5e946f/go.mod h1:apktt6TleWtCIwpz63vBqUnw8MX8gWKoZyxgDpXFtgM= github.com/gogf/gf/v2 v2.0.0-rc3 h1:FkmLFhgOCZnyr24H/Yj9V1psS7fJ79DtPuSz+l/kwsc= github.com/gogf/gf/v2 v2.0.0-rc3/go.mod h1:apktt6TleWtCIwpz63vBqUnw8MX8gWKoZyxgDpXFtgM= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -52,6 +52,8 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0= +github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -71,14 +73,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tiger1103/gfast-cache v0.0.0-20220223064531-4c6d4203c3a1 h1:Ya2wRvt2I4puc5xNWF2qL3gxXogG4SPb6WA7PDFcEhI= -github.com/tiger1103/gfast-cache v0.0.0-20220223064531-4c6d4203c3a1/go.mod h1:s6cRWyr87wz6IJNGKRV6Ahq9hcuVz8h2PAtGrO66JO8= -github.com/tiger1103/gfast-cache v0.0.1 h1:L71xvKUyH0WX1sZ4ZUlJbHssfSbFmoW3MjMfOJEpgDY= -github.com/tiger1103/gfast-cache v0.0.1/go.mod h1:s6cRWyr87wz6IJNGKRV6Ahq9hcuVz8h2PAtGrO66JO8= -github.com/tiger1103/gfast-cache v0.0.2 h1:MLQrFooBRV5IvSoHyChB3Wcarhfsxo4oGa95ZB9vLmM= -github.com/tiger1103/gfast-cache v0.0.2/go.mod h1:s6cRWyr87wz6IJNGKRV6Ahq9hcuVz8h2PAtGrO66JO8= -github.com/tiger1103/gfast-token v0.0.1 h1:fVyfDyUZkQI9m7eOKc3/GtdD4qSHsvlhvGFxEoXTrZI= -github.com/tiger1103/gfast-token v0.0.1/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI= @@ -90,6 +84,8 @@ go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH81 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 h1:TbGuee8sSq15Iguxu4deQ7+Bqq/d2rsQejGcEtADAMQ= +golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/internal/app/common/controller/captcah.go b/internal/app/common/controller/captcah.go new file mode 100644 index 0000000..e735179 --- /dev/null +++ b/internal/app/common/controller/captcah.go @@ -0,0 +1,29 @@ +/* +* @desc:验证码获取 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 17:45 + */ + +package controller + +import ( + "context" + "github.com/tiger1103/gfast/v3/apiv1/common" + "github.com/tiger1103/gfast/v3/internal/app/common/service" +) + +var Captcha = cCaptcha{} + +type cCaptcha struct { +} + +// Get 获取验证码 +func (c *cCaptcha) Get(ctx context.Context, req *common.CaptchaReq) (res *common.CaptchaRes, err error) { + idKeyC, base64stringC := service.Captcha.GetVerifyImgString(ctx) + res = &common.CaptchaRes{ + Key: idKeyC, + Img: base64stringC, + } + return +} diff --git a/internal/app/common/router/router.go b/internal/app/common/router/router.go new file mode 100644 index 0000000..3194e01 --- /dev/null +++ b/internal/app/common/router/router.go @@ -0,0 +1,25 @@ +/* +* @desc:后台路由 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/2/18 17:34 + */ + +package router + +import ( + "github.com/gogf/gf/v2/net/ghttp" + "github.com/tiger1103/gfast/v3/internal/app/common/controller" + "github.com/tiger1103/gfast/v3/library/libMiddleware" +) + +func BindController(group *ghttp.RouterGroup) { + group.Group("/pub", func(group *ghttp.RouterGroup) { + group.Middleware(libMiddleware.ExceptionHandle) + group.Group("/captcha", func(group *ghttp.RouterGroup) { + group.Bind( + controller.Captcha, + ) + }) + }) +} diff --git a/internal/app/common/service/captcha.go b/internal/app/common/service/captcha.go new file mode 100644 index 0000000..609b05f --- /dev/null +++ b/internal/app/common/service/captcha.go @@ -0,0 +1,40 @@ +package service + +import ( + "context" + "github.com/gogf/gf/v2/text/gstr" + "github.com/mojocn/base64Captcha" + "github.com/tiger1103/gfast/v3/library/liberr" +) + +type captcha struct{} + +var Captcha = new(captcha) + +// GetVerifyImgString 获取字母数字混合验证码 +func (s *captcha) GetVerifyImgString(ctx context.Context) (idKeyC string, base64stringC string) { + driver := &base64Captcha.DriverString{ + Height: 80, + Width: 240, + NoiseCount: 50, + ShowLineOptions: 20, + Length: 4, + Source: "abcdefghjkmnpqrstuvwxyz23456789", + Fonts: []string{"chromohv.ttf"}, + } + driver = driver.ConvertFonts() + store := base64Captcha.DefaultMemStore + c := base64Captcha.NewCaptcha(driver, store) + idKeyC, base64stringC, err := c.Generate() + liberr.ErrIsNil(ctx, err) + return +} + +// VerifyString 验证输入的验证码是否正确 +func (s *captcha) VerifyString(id, answer string) bool { + driver := new(base64Captcha.DriverString) + store := base64Captcha.DefaultMemStore + c := base64Captcha.NewCaptcha(driver, store) + answer = gstr.ToLower(answer) + return c.Verify(id, answer, true) +} diff --git a/internal/app/demo/controller/demo.go b/internal/app/demo/controller/demo.go new file mode 100644 index 0000000..7219ecb --- /dev/null +++ b/internal/app/demo/controller/demo.go @@ -0,0 +1,24 @@ +/* +* @desc:demo +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 15:24 + */ + +package controller + +import ( + "context" + "github.com/tiger1103/gfast/v3/apiv1/demo" +) + +var Demo = cDemo{} + +type cDemo struct { +} + +func (c *cDemo) Demo(ctx context.Context, req *demo.DmReq) (res *demo.DmRes, err error) { + res = &demo.DmRes{Name: "赵四"} + panic("demo wrong") + return +} diff --git a/internal/app/demo/router/router.go b/internal/app/demo/router/router.go new file mode 100644 index 0000000..c3ab75d --- /dev/null +++ b/internal/app/demo/router/router.go @@ -0,0 +1,24 @@ +/* +* @desc:demo +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 15:28 + */ + +package router + +import ( + "github.com/gogf/gf/v2/net/ghttp" + "github.com/tiger1103/gfast/v3/internal/app/demo/controller" + "github.com/tiger1103/gfast/v3/library/libMiddleware" +) + +func BindController(group *ghttp.RouterGroup) { + group.Group("/demo", func(group *ghttp.RouterGroup) { + group.Middleware(libMiddleware.ExceptionHandle) + group.Bind( + controller.Demo, + ) + }) + +} diff --git a/internal/system/consts/consts.go b/internal/app/system/consts/consts.go similarity index 100% rename from internal/system/consts/consts.go rename to internal/app/system/consts/consts.go diff --git a/internal/system/controller/hello.go b/internal/app/system/controller/hello.go similarity index 63% rename from internal/system/controller/hello.go rename to internal/app/system/controller/hello.go index 2d22cff..f5bc81c 100644 --- a/internal/system/controller/hello.go +++ b/internal/app/system/controller/hello.go @@ -2,7 +2,6 @@ package controller import ( "context" - "github.com/gogf/gf/v2/frame/g" "github.com/tiger1103/gfast/v3/apiv1/system" ) @@ -14,6 +13,10 @@ var ( type cHello struct{} func (h *cHello) Hello(ctx context.Context, req *system.HelloReq) (res *system.HelloRes, err error) { - g.RequestFromCtx(ctx).Response.Writeln("Hello World!") + g.Log().Debug(ctx, "demo test") + //g.RequestFromCtx(ctx).Response.Writeln("Hello World!") + res = &system.HelloRes{ + Data: g.Map{"name": "zhangsang", "age": 18}, + } return } diff --git a/internal/system/model/.gitkeep b/internal/app/system/model/.gitkeep similarity index 100% rename from internal/system/model/.gitkeep rename to internal/app/system/model/.gitkeep diff --git a/internal/system/model/entity/.gitkeep b/internal/app/system/model/entity/.gitkeep similarity index 100% rename from internal/system/model/entity/.gitkeep rename to internal/app/system/model/entity/.gitkeep diff --git a/internal/app/system/model/entity/sys_user.go b/internal/app/system/model/entity/sys_user.go new file mode 100644 index 0000000..3bd7c51 --- /dev/null +++ b/internal/app/system/model/entity/sys_user.go @@ -0,0 +1,34 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23 +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// SysUser is the golang structure for table sys_user. +type SysUser struct { + Id uint64 `json:"id" description:""` + UserName string `json:"userName" description:"用户名"` + Mobile string `json:"mobile" description:"中国手机不带国家代码,国际手机号格式为:国家代码-手机号"` + UserNickname string `json:"userNickname" description:"用户昵称"` + Birthday int `json:"birthday" description:"生日"` + UserPassword string `json:"userPassword" description:"登录密码;cmf_password加密"` + UserSalt string `json:"userSalt" description:"加密盐"` + UserStatus uint `json:"userStatus" description:"用户状态;0:禁用,1:正常,2:未验证"` + UserEmail string `json:"userEmail" description:"用户登录邮箱"` + Sex int `json:"sex" description:"性别;0:保密,1:男,2:女"` + Avatar string `json:"avatar" description:"用户头像"` + DeptId uint64 `json:"deptId" description:"部门id"` + Remark string `json:"remark" description:"备注"` + IsAdmin int `json:"isAdmin" description:"是否后台管理员 1 是 0 否"` + Address string `json:"address" description:"联系地址"` + Describe string `json:"describe" description:"描述信息"` + LastLoginIp string `json:"lastLoginIp" description:"最后登录ip"` + LastLoginTime *gtime.Time `json:"lastLoginTime" description:"最后登录时间"` + CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"` + UpdatedAt *gtime.Time `json:"updatedAt" description:"更新时间"` + DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"` +} diff --git a/internal/system/packed/packed.go b/internal/app/system/packed/packed.go similarity index 100% rename from internal/system/packed/packed.go rename to internal/app/system/packed/packed.go diff --git a/internal/app/system/router/router.go b/internal/app/system/router/router.go new file mode 100644 index 0000000..53b2cac --- /dev/null +++ b/internal/app/system/router/router.go @@ -0,0 +1,23 @@ +/* +* @desc:后台路由 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/2/18 17:34 + */ + +package router + +import ( + "github.com/gogf/gf/v2/net/ghttp" + "github.com/tiger1103/gfast/v3/internal/app/system/controller" + "github.com/tiger1103/gfast/v3/library/libMiddleware" +) + +func BindController(group *ghttp.RouterGroup) { + group.Group("/system", func(group *ghttp.RouterGroup) { + group.Middleware(libMiddleware.ExceptionHandle) + group.Bind( + controller.Hello, + ) + }) +} diff --git a/internal/system/service/.gitkeep b/internal/app/system/service/.gitkeep similarity index 100% rename from internal/system/service/.gitkeep rename to internal/app/system/service/.gitkeep diff --git a/internal/system/service/internal/dao/.gitkeep b/internal/app/system/service/internal/dao/.gitkeep similarity index 100% rename from internal/system/service/internal/dao/.gitkeep rename to internal/app/system/service/internal/dao/.gitkeep diff --git a/internal/app/system/service/internal/dao/internal/sys_user.go b/internal/app/system/service/internal/dao/internal/sys_user.go new file mode 100644 index 0000000..2d2e012 --- /dev/null +++ b/internal/app/system/service/internal/dao/internal/sys_user.go @@ -0,0 +1,112 @@ +// ========================================================================== +// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23 +// ========================================================================== + +package internal + +import ( + "context" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// SysUserDao is the data access object for table sys_user. +type SysUserDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns SysUserColumns // columns contains all the column names of Table for convenient usage. +} + +// SysUserColumns defines and stores column names for table sys_user. +type SysUserColumns struct { + Id string // + UserName string // 用户名 + Mobile string // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号 + UserNickname string // 用户昵称 + Birthday string // 生日 + UserPassword string // 登录密码;cmf_password加密 + UserSalt string // 加密盐 + UserStatus string // 用户状态;0:禁用,1:正常,2:未验证 + UserEmail string // 用户登录邮箱 + Sex string // 性别;0:保密,1:男,2:女 + Avatar string // 用户头像 + DeptId string // 部门id + Remark string // 备注 + IsAdmin string // 是否后台管理员 1 是 0 否 + Address string // 联系地址 + Describe string // 描述信息 + LastLoginIp string // 最后登录ip + LastLoginTime string // 最后登录时间 + CreatedAt string // 创建时间 + UpdatedAt string // 更新时间 + DeletedAt string // 删除时间 +} + +// sysUserColumns holds the columns for table sys_user. +var sysUserColumns = SysUserColumns{ + Id: "id", + UserName: "user_name", + Mobile: "mobile", + UserNickname: "user_nickname", + Birthday: "birthday", + UserPassword: "user_password", + UserSalt: "user_salt", + UserStatus: "user_status", + UserEmail: "user_email", + Sex: "sex", + Avatar: "avatar", + DeptId: "dept_id", + Remark: "remark", + IsAdmin: "is_admin", + Address: "address", + Describe: "describe", + LastLoginIp: "last_login_ip", + LastLoginTime: "last_login_time", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", +} + +// NewSysUserDao creates and returns a new DAO object for table data access. +func NewSysUserDao() *SysUserDao { + return &SysUserDao{ + group: "default", + table: "sys_user", + columns: sysUserColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *SysUserDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *SysUserDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *SysUserDao) Columns() SysUserColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *SysUserDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *SysUserDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *SysUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/app/system/service/internal/dao/sys_user.go b/internal/app/system/service/internal/dao/sys_user.go new file mode 100644 index 0000000..b25b24c --- /dev/null +++ b/internal/app/system/service/internal/dao/sys_user.go @@ -0,0 +1,24 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "github.com/tiger1103/gfast/v3/internal/app/system/service/internal/dao/internal" +) + +// sysUserDao is the data access object for table sys_user. +// You can define custom methods on it to extend its functionality as you wish. +type sysUserDao struct { + *internal.SysUserDao +} + +var ( + // SysUser is globally public accessible object for table sys_user operations. + SysUser = sysUserDao{ + internal.NewSysUserDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/system/service/internal/do/.gitkeep b/internal/app/system/service/internal/do/.gitkeep similarity index 100% rename from internal/system/service/internal/do/.gitkeep rename to internal/app/system/service/internal/do/.gitkeep diff --git a/internal/app/system/service/internal/do/sys_user.go b/internal/app/system/service/internal/do/sys_user.go new file mode 100644 index 0000000..9f39673 --- /dev/null +++ b/internal/app/system/service/internal/do/sys_user.go @@ -0,0 +1,36 @@ +// ================================================================================= +// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-03-02 16:48:23 +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +// SysUser is the golang structure of table sys_user for DAO operations like Where/Data. +type SysUser struct { + g.Meta `orm:"table:sys_user, do:true"` + Id interface{} // + UserName interface{} // 用户名 + Mobile interface{} // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号 + UserNickname interface{} // 用户昵称 + Birthday interface{} // 生日 + UserPassword interface{} // 登录密码;cmf_password加密 + UserSalt interface{} // 加密盐 + UserStatus interface{} // 用户状态;0:禁用,1:正常,2:未验证 + UserEmail interface{} // 用户登录邮箱 + Sex interface{} // 性别;0:保密,1:男,2:女 + Avatar interface{} // 用户头像 + DeptId interface{} // 部门id + Remark interface{} // 备注 + IsAdmin interface{} // 是否后台管理员 1 是 0 否 + Address interface{} // 联系地址 + Describe interface{} // 描述信息 + LastLoginIp interface{} // 最后登录ip + LastLoginTime *gtime.Time // 最后登录时间 + CreatedAt *gtime.Time // 创建时间 + UpdatedAt *gtime.Time // 更新时间 + DeletedAt *gtime.Time // 删除时间 +} diff --git a/internal/system/cmd/cmd.go b/internal/cmd/cmd.go similarity index 99% rename from internal/system/cmd/cmd.go rename to internal/cmd/cmd.go index 20b69dd..07595cf 100644 --- a/internal/system/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -2,13 +2,12 @@ package cmd import ( "context" - "github.com/gogf/gf/v2/protocol/goai" - consts "github.com/tiger1103/gfast/v3/internal/const" - "github.com/tiger1103/gfast/v3/internal/router" - "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/gcmd" + "github.com/gogf/gf/v2/protocol/goai" + consts "github.com/tiger1103/gfast/v3/internal/const" + "github.com/tiger1103/gfast/v3/internal/router" ) var ( @@ -29,7 +28,6 @@ var ( } ) - func enhanceOpenAPIDoc(s *ghttp.Server) { openapi := s.GetOpenApi() openapi.Config.CommonResponse = ghttp.DefaultHandlerResponse{} @@ -44,4 +42,4 @@ func enhanceOpenAPIDoc(s *ghttp.Server) { URL: consts.OpenAPIContactUrl, }, } -} \ No newline at end of file +} diff --git a/internal/router/router.go b/internal/router/router.go index 34a7881..7d155a2 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -9,10 +9,16 @@ package router import ( "github.com/gogf/gf/v2/net/ghttp" - systemRouter "github.com/tiger1103/gfast/v3/internal/system/router" + commonRouter "github.com/tiger1103/gfast/v3/internal/app/common/router" + demoRouter "github.com/tiger1103/gfast/v3/internal/app/demo/router" + systemRouter "github.com/tiger1103/gfast/v3/internal/app/system/router" ) func BindController(group *ghttp.RouterGroup) { // 绑定后台路由 systemRouter.BindController(group) + // 绑定测试路由 + demoRouter.BindController(group) + // 绑定公共路由 + commonRouter.BindController(group) } diff --git a/internal/system/router/router.go b/internal/system/router/router.go deleted file mode 100644 index b5dbf33..0000000 --- a/internal/system/router/router.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -* @desc:后台路由 -* @company:云南奇讯科技有限公司 -* @Author: yixiaohu -* @Date: 2022/2/18 17:34 - */ - -package router - -import ( - "github.com/gogf/gf/v2/net/ghttp" - "github.com/tiger1103/gfast/v3/internal/system/controller" -) - -func BindController(group *ghttp.RouterGroup) { - group.Bind( - controller.Hello, - ) -} \ No newline at end of file diff --git a/library/libMiddleware/middleware.go b/library/libMiddleware/middleware.go new file mode 100644 index 0000000..3fe005a --- /dev/null +++ b/library/libMiddleware/middleware.go @@ -0,0 +1,28 @@ +/* +* @desc:公用中间件 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 15:16 + */ + +package libMiddleware + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/text/gstr" +) + +// ExceptionHandle 异常处理 +func ExceptionHandle(r *ghttp.Request) { + r.Middleware.Next() + if err := r.GetError(); err != nil { + msg := err.Error() + pos := gstr.Pos(msg, ":") + if pos > 0 { + msg = gstr.SubStr(msg, pos+2) + } + r.Response.ClearBuffer() + r.Response.WriteJson(g.Map{"code": 500, "message": msg}) + } +} diff --git a/library/liberr/err.go b/library/liberr/err.go new file mode 100644 index 0000000..7160005 --- /dev/null +++ b/library/liberr/err.go @@ -0,0 +1,24 @@ +/* +* @desc:错误处理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2022/3/2 14:53 + */ + +package liberr + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" +) + +func ErrIsNil(ctx context.Context, err error, msg ...string) { + if err != nil { + g.Log().Error(ctx, err.Error()) + if len(msg) > 0 { + panic(msg[0]) + } else { + panic(err.Error()) + } + } +} diff --git a/main.go b/main.go index f98fa01..16a47f0 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,15 @@ package main import ( - _ "github.com/tiger1103/gfast/v3/internal/system/packed" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" + _ "github.com/tiger1103/gfast/v3/internal/app/system/packed" "github.com/gogf/gf/v2/os/gctx" - "github.com/tiger1103/gfast/v3/internal/system/cmd" + "github.com/tiger1103/gfast/v3/internal/cmd" ) func main() { + g.Log().SetFlags(glog.F_ASYNC | glog.F_TIME_DATE | glog.F_TIME_TIME | glog.F_FILE_LONG) cmd.Main.Run(gctx.New()) } diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index 45a389a..abbe5e6 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -24,4 +24,15 @@ logger: stdout: true +# CLI. +gfcli: + gen: + dao: + - link: "mysql:root:123456@tcp(127.0.0.1:3306)/gfast-v3" + tables: "sys_user" + removePrefix: "gf_" + descriptionTag: true + noModelComment: true + path: "./internal/app/system" +