公共方法库

lingxin c5623e401b 日志 há 3 semanas atrás
.idea 82a26f5c72 first commit há 11 meses atrás
lxCommon f5f69f2a56 同时开两个事务的方法 há 2 meses atrás
lxDb ce4d32530b 同时开两个事务的方法 há 7 meses atrás
lxLock 32e3d99d37 redis há 11 meses atrás
lxUtil c28cf29933 123 há 11 meses atrás
lxcors 2937bf6579 xxx há 11 meses atrás
lxlog 2937bf6579 xxx há 11 meses atrás
lxrun fa00f01a95 日志 há 2 meses atrás
lxzap fa00f01a95 日志 há 2 meses atrás
README.md fa00f01a95 日志 há 2 meses atrás
go.mod c5623e401b 日志 há 3 semanas atrás
go.sum c5623e401b 日志 há 3 semanas atrás
lxutils.go c5623e401b 日志 há 3 semanas atrás

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