公共方法库

lingxin ce4d32530b 同时开两个事务的方法 1 month ago
.idea 82a26f5c72 first commit 5 months ago
lxCommon 5bdfa75392 123 5 months ago
lxDb ce4d32530b 同时开两个事务的方法 1 month ago
lxLock 32e3d99d37 redis 5 months ago
lxUtil c28cf29933 123 5 months ago
lxcors 2937bf6579 xxx 5 months ago
lxlog 2937bf6579 xxx 5 months ago
lxrun 4fb99540c5 支持多个db 2 months ago
lxzap 32e3d99d37 redis 5 months ago
README.md a1b10987f0 123 5 months ago
go.mod 32e3d99d37 redis 5 months ago
go.sum 32e3d99d37 redis 5 months ago
lxutils.go 82a26f5c72 first commit 5 months ago

README.md

Getting Started

Installing

To start using LxUtils, install Go and run go get:

$ go get -u git.listensoft.net/tool/lxutils

Get a value

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.LogConfig{
		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表示管理员"`
}