lib

package
v0.0.0-...-b42d4c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Log         *zap.SugaredLogger
	EmailCfg    = &EmailCfgParam{}
	RedisCfg    = &RedisCfgParam{}
	RedisClient *redis.Client
	DBCfg       = &DBCfgParam{}
	DB          *sqlx.DB
	MinioCfg    = &MinioCfgParam{}
	Minio       = &MinioClient{}
)
View Source
var (
	Trans ut.Translator
)

Functions

func InitValidateTrans

func InitValidateTrans(validate *validator.Validate) ut.Translator

func RandCheckCode

func RandCheckCode(n int) string

随机验证码

func RandString

func RandString(base string, n int) string

RandString randomly generate a specified length string based on the given string 依据给定字符串生成给定长度的随机字符串

func ServerFail

func ServerFail(ctx *gin.Context, err error) bool

服务器错误,判断异常是否为空,为空返回true,非空返回false并向客户端发送服务器错误信息

func ServerFailf

func ServerFailf(ctx *gin.Context, code int, msg string, err error) bool

服务器错误,判断异常是否为空,为空返回true,非空返回false并向客户端发送服务器错误信息

func ServerResult

func ServerResult(ctx *gin.Context, code int, msg string, data any, err error)

统一响应方法

func ServerSuccess

func ServerSuccess(ctx *gin.Context, msg string, data any)

统一成功响应方法

func ShouldBind

func ShouldBind(ctx *gin.Context, obj any) bool

参数绑定封装,仅只需要判断为false则return即可

func ShouldBindJSON

func ShouldBindJSON(ctx *gin.Context, obj any) bool

参数绑定封装,仅只需要判断为false则return即可

func TransError

func TransError(err error) string

func UID

func UID() string

获取UUID (转大写,不带-)

Types

type DBCfgParam

type DBCfgParam struct {
	Host      string `toml:"host"`      // 数据库地址 127.0.0.1:3306
	User      string `toml:"user"`      // 数据库用户名
	Password  string `toml:"password"`  // 数据库密码
	Database  string `toml:"database"`  // 数据库名
	Charset   string `toml:"charset"`   // 数据库字符集 utf8mb4
	ParseTime string `toml:"parseTime"` // 是否分析时间 True
	Loc       string `toml:"loc"`       // loc Local
}

func (*DBCfgParam) Connect

func (dp *DBCfgParam) Connect() (*sqlx.DB, error)

func (*DBCfgParam) DSN

func (dp *DBCfgParam) DSN() string

type EmailCfgParam

type EmailCfgParam struct {
	Name     string `toml:"name" xml:"name" json:"name"`             // 发送者名称
	MailAddr string `toml:"mailAddr" xml:"mailAddr" json:"mailAddr"` // 发送者邮箱地址 youemail@email.com
	SmtpAddr string `toml:"smtpAddr" xml:"smtpAddr" json:"smtpAddr"` // 邮箱服务器地址(包含端口号)非SSL协议: 例如网易的 smtp.163.com:25
	HostAddr string `toml:"hostAddr" xml:"hostAddr" json:"hostAddr"` // 登录授权时服务器地址,不包含端口号: 例如网易的 smtp.163.com
	Password string `toml:"password" xml:"password" json:"password"` // 发送者邮箱授权密钥
	IsStatus bool   // 是否启用
}

邮箱配置

func (*EmailCfgParam) Send

func (ep *EmailCfgParam) Send(to string, title, message string) error

发送邮件方法 (正文方式)

func (*EmailCfgParam) SendHtml

func (ep *EmailCfgParam) SendHtml(to string, title, html string) error

发送邮件方法 (网页方式)

type MinioCfgParam

type MinioCfgParam struct {
	EndPoint  string `toml:"endPoint"`  // minio服务器地址 服务ID-地址
	AccessKey string `toml:"accessKey"` // minio 访问密钥
	SecretKey string `toml:"secretKey"` // minio 保密密钥
	UseSSL    bool   `toml:"useSSL"`    // minio 服务协议是否使用https

	Bucket string `toml:"bucket"` // 文件上传使用的桶
}

MinioCfgParam minio参数配置

func (*MinioCfgParam) Connect

func (mcp *MinioCfgParam) Connect() (*minio.Client, error)

type MinioClient

type MinioClient struct {
	// contains filtered or unexported fields
}

MinioClient minio服务

func (*MinioClient) FGetObject

func (m *MinioClient) FGetObject(bucket, objectName, filePath string) error

FGetObject 获取文件

func (*MinioClient) FPutObject

func (m *MinioClient) FPutObject(bucket, region, objectName, filePath string) error

FPutObject 文件上传

func (*MinioClient) GetClient

func (m *MinioClient) GetClient() *minio.Client

获取客户端

func (*MinioClient) GetObject

func (m *MinioClient) GetObject(bucket, objectName string) ([]byte, error)

GetObject 获取文件

func (*MinioClient) MakeBucket

func (m *MinioClient) MakeBucket(bucket string, region string) error

MakeBucket 创建minio桶

func (*MinioClient) PutObject

func (m *MinioClient) PutObject(bucket, region, objectName string, file io.Reader, fileSize int64) error

PutObject 文件上传

func (*MinioClient) SetClient

func (m *MinioClient) SetClient(cli *minio.Client)

设置客户端

type RedisCfgParam

type RedisCfgParam struct {
	Host     string `toml:"host"`     // 地址 127.0.0.1:6379
	Password string `toml:"password"` // 密码
	DB       int    `toml:"db"`       // 默认连接库
}

Redis配置

func (*RedisCfgParam) NewClient

func (rc *RedisCfgParam) NewClient() *redis.Client

获取Redis Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL