Просмотр исходного кода

项目目录划分,错误处理,验证码获取

yxh 4 лет назад
Родитель
Сommit
37b2c9c55b

+ 3 - 1
.gitignore

@@ -18,4 +18,6 @@ cbuild
 main
 output/
 manifest/output/
-*.exe
+*.exe
+tmp/
+resource/log/

+ 19 - 0
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"`
+}

+ 18 - 0
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"`
+}

+ 1 - 0
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"`
 }

+ 1 - 2
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
 )

+ 6 - 10
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=

+ 29 - 0
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
+}

+ 25 - 0
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,
+			)
+		})
+	})
+}

+ 40 - 0
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)
+}

+ 24 - 0
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
+}

+ 24 - 0
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,
+		)
+	})
+
+}

+ 0 - 0
internal/system/consts/consts.go → internal/app/system/consts/consts.go


+ 5 - 2
internal/system/controller/hello.go → 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
 }

+ 0 - 0
internal/system/model/.gitkeep → internal/app/system/model/.gitkeep


+ 0 - 0
internal/system/model/entity/.gitkeep → internal/app/system/model/entity/.gitkeep


+ 34 - 0
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:"删除时间"`
+}

+ 0 - 0
internal/system/packed/packed.go → internal/app/system/packed/packed.go


+ 23 - 0
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,
+		)
+	})
+}

+ 0 - 0
internal/system/service/.gitkeep → internal/app/system/service/.gitkeep


+ 0 - 0
internal/system/service/internal/dao/.gitkeep → internal/app/system/service/internal/dao/.gitkeep


+ 112 - 0
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)
+}

+ 24 - 0
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.

+ 0 - 0
internal/system/service/internal/do/.gitkeep → internal/app/system/service/internal/do/.gitkeep


+ 36 - 0
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 // 删除时间
+}

+ 4 - 6
internal/system/cmd/cmd.go → 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,
 		},
 	}
-}
+}

+ 7 - 1
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)
 }

+ 0 - 19
internal/system/router/router.go

@@ -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,
-	)
-}

+ 28 - 0
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})
+	}
+}

+ 24 - 0
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())
+		}
+	}
+}

+ 5 - 2
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())
 }

+ 11 - 0
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"
+