lxutils/README.md
2025-08-11 12:07:33 +08:00

89 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Getting Started
===============
## Installing
To start using LxUtils, install Go and run `go get`:
```sh
$ go get -u git.listensoft.net/tool/lxutils
```
```version
v1.0.0
```
## Get a value
Go.
```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表示管理员"`
}
```
## 版本变更记录(从v1.0.5开始记录)
### v1.0.5 2025-08-02
#### 变更
- 修改GORM封装方法中的AND使其代替原本的Ors函数防止SQL注入
### v1.0.7 2025-08-11
#### 变更
- 修改日志打印栈信息