lingxin c5623e401b 日志 | 2 сар өмнө | |
---|---|---|
.idea | 1 жил өмнө | |
lxCommon | 3 сар өмнө | |
lxDb | 9 сар өмнө | |
lxLock | 1 жил өмнө | |
lxUtil | 1 жил өмнө | |
lxcors | 1 жил өмнө | |
lxlog | 1 жил өмнө | |
lxrun | 3 сар өмнө | |
lxzap | 3 сар өмнө | |
README.md | 3 сар өмнө | |
go.mod | 2 сар өмнө | |
go.sum | 2 сар өмнө | |
lxutils.go | 2 сар өмнө |
To start using LxUtils, install Go and run go get
:
$ go get -u git.listensoft.net/tool/lxutils
Go.
package main
import (
"fmt"
"git.listensoft.net/tool/lxutils/lxCommon"
"git.listensoft.net/tool/lxutils/lxDb"
"git.listensoft.net/tool/lxutils/lxrun"
"git.listensoft.net/tool/lxutils/lxzap"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"time"
)
func main() {
//lxutils.Aa()
lxrun.Run("prod", "8989", func() {
//可执行定时器等等
fmt.Println("run cron、mq")
}, router, lxzap.ZapLogConfig{
Level: "info",
Filename: "zap.log",
MaxSize: 2,
MaxAge: 1000,
MaxBackups: 10000,
}, lxDb.DbConfig{
Host: "xxxxxxx",
Port: "3306",
User: "xxxxxx",
Password: "xxxxx",
Database: "etax",
Charset: "utf8mb4",
}, lxDb.RedisConfig{})
}
func router(router *gin.Engine) {
router.GET("/server", func(c *gin.Context) {
lxzap.Log("测试log", c)
lxDb.GetDB(c).Model(User{BaseModel: BaseModel{ID: 12}}).First(&User{})
lxCommon.Ok(c, "")
})
}
type BaseModel struct {
ID int32 `gorm:"primary_key;comment:ID"`
CreatedAt time.Time `gorm:"column:add_time;comment:创建时间"`
UpdatedAt time.Time `gorm:"column:update_time;comment:更新时间"`
DeletedAt gorm.DeletedAt `gorm:"comment:删除时间"`
IsDeleted bool `gorm:"comment:是否删除"`
}
type User struct {
BaseModel
Mobile string `gorm:"index:idx_mobile;unique;type:varchar(11);not null;comment:手机号"`
Password string `gorm:"type:varchar(100);not null;comment:密码"`
NickName string `gorm:"type:varchar(20);comment:账号名称"`
Birthday *time.Time `gorm:"type:datetime;comment:出生日期"`
Gender string `gorm:"column:gender;default:male;type:varchar(6);comment:femail表示女,male表示男"`
Role int `gorm:"column:role;default:1;type:int;comment:1表示普通用户,2表示管理员"`
}