utils

package
v0.0.0-...-3a020dc Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package utils @file : p.crypt.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:49 @Description:

Package utils @file : db.log.go @author : china.gdxs@gmail.com @time : 2023/11/9 17:44 @Description:

Package utils @file : p.email.go @author : xs @time : 2024/6/17 13:59 @Description: 邮件警告通知

Package jwt_auth @author: ekin @date: 2022/5/31 @Description: jwt token解析

Package utils @file : p.db.go @author : china.gdxs@gmail.com @time : 2023/11/9 16:18 @Description:

Package utils @file : p.redis.go @author : china.gdxs@gmail.com @time : 2023/11/10 09:08 @Description: redis config

Package utils @file : p.viper.go @author : china.gdxs@gmail.com @time : 2023/11/9 16:11 @Description:

Package utils @file : providers.go @author : china.gdxs@gmail.com @time : 2023/11/9 16:08 @Description: utils

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = errors.New("【jwt_auth】invalid auth token")
	ErrNoClaims     = errors.New("【jwt_auth】no auth params")
)

var ProviderSet = wire.NewSet(NewJwtAuth, NewOps)

Functions

func NewGorm

func NewGorm(v *viper.Viper, lg logger.Interface) (db *gorm.DB, fc func(), err error)

NewGorm gorm v 基础配置 lg gorm 日志文件

func NewGormLog

func NewGormLog(v *viper.Viper, l *zap.Logger) (res logger.Interface, err error)

NewGormLog 注意等级, 不配置表示沉默 trace 不记录任何日志

func NewLog

func NewLog(v *viper.Viper) (l *zap.Logger, fc func(), err error)

NewLog for init zap log library

func NewRedis

func NewRedis(v *viper.Viper) (rdb *redis.Client, err error)

func NewViper

func NewViper(path string) (v *viper.Viper, err error)

NewViper 初始化viper

func TraceCtx

func TraceCtx(ctx context.Context) context.Context

TraceCtx 异步执行,链路最终 去除超时机制

func WithCtx

func WithCtx(ctx context.Context, log *zap.Logger) *zap.Logger

Types

type Crypt

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

func NewCrypt

func NewCrypt(viper *viper.Viper) *Crypt

func NewCryptByKey

func NewCryptByKey(key string) *Crypt

func (*Crypt) AesDe2Str

func (this *Crypt) AesDe2Str(str string) (result string, err error)

AesDe2Str 手机号码解析

func (*Crypt) AesEn2Str

func (this *Crypt) AesEn2Str(str string) (result string, err error)

AesEn2Str aes str 加密

type GormLog

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

func (*GormLog) Error

func (l *GormLog) Error(ctx context.Context, msg string, data ...any)

func (*GormLog) Info

func (l *GormLog) Info(ctx context.Context, msg string, data ...any)

func (*GormLog) LogMode

func (l *GormLog) LogMode(level logger.LogLevel) logger.Interface

func (*GormLog) Trace

func (l *GormLog) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLog) Warn

func (l *GormLog) Warn(ctx context.Context, msg string, data ...any)

func (*GormLog) WithCtx

func (l *GormLog) WithCtx(ctx context.Context) *zap.Logger

type GormOpts

type GormOpts struct {
	Host                   string        `yaml:"host"`     // ip
	Port                   int32         `yaml:"port"`     // 端口
	Database               string        `yaml:"database"` // 表名称
	User                   string        `yaml:"user"`     // 用户名
	Pwd                    string        `yaml:"pwd"`      // 密码
	PreFix                 string        `yaml:"prefix"`   // 表前缀
	MaxIdleConn            int           `yaml:"maxIdleConn"`
	MaxOpenConn            int           `yaml:"maxOpenConn"`     // 最大链接池数
	ConnMaxLifetime        time.Duration `yaml:"connMaxLifetime"` // 单个链接有效时长
	Level                  string        `yaml:"level"`
	SlowThreshold          time.Duration `yaml:"slowTime"`               // 慢查询阀值
	SkipDefaultTransaction bool          `yaml:"skipDefaultTransaction"` // true 开启禁用事物,大约 30%+ 性能提升
	SingularTable          bool          `yaml:"singularTable"`
}

type JwtAuth

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

func NewJwtAuth

func NewJwtAuth(o *JwtOpts) *JwtAuth

func (*JwtAuth) CreateTokenWithMapPayload

func (a *JwtAuth) CreateTokenWithMapPayload(payloads map[string]interface{}, seconds int64) (string, error)

create token with map

func (*JwtAuth) NeedCheck

func (a *JwtAuth) NeedCheck(path string) bool

need check sign

func (*JwtAuth) SetPath

func (a *JwtAuth) SetPath(paths ...string) *JwtAuth

setting match paths

func (*JwtAuth) SetPrefix

func (a *JwtAuth) SetPrefix(paths ...string) *JwtAuth

setting prefix paths

func (*JwtAuth) SetSecret

func (a *JwtAuth) SetSecret(secret string) *JwtAuth

setting secret

func (*JwtAuth) SetWhitelist

func (a *JwtAuth) SetWhitelist(paths ...string) *JwtAuth

setting whitelist paths

func (*JwtAuth) Verifier

func (a *JwtAuth) Verifier(r *http.Request) (jwt.MapClaims, error)

verifier the token

type JwtOpts

type JwtOpts struct {
	Secret    string   `yaml:"secret"`
	Path      []string `yaml:"path"`
	Prefix    []string `yaml:"prefix"`
	Whitelist []string `yaml:"whitelist"`
}

func NewJWTOps

func NewJWTOps(v *viper.Viper) (*JwtOpts, error)

type Log

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

func NewWLog

func NewWLog(lg *zap.Logger) *Log

func (Log) WithCtx

func (this Log) WithCtx(ctx context.Context) *zap.Logger

type LogOpts

type LogOpts struct {
	Filename    string `yaml:"filename"`    // 文件名称
	MaxSize     int    `yaml:"maxSize"`     // 最大文件
	MaxBackups  int    `yaml:"maxBackups"`  // 最大备份数
	MaxAge      int    `yaml:"maxAge"`      //保留时长天 days
	Level       string `yaml:"level"`       // 日志登记 对应zap.level
	Stdout      bool   `yaml:"stdout"`      // 是否在终端输出
	Compress    bool   `yaml:"compress"`    // 是否压缩文件
	LocalTime   bool   `yaml:"localTime"`   // 使用本地时间
	IsContainer bool   `yaml:"isContainer"` // 是否是容器, 容器存在公用app.log 情况可以按容器ip 区分
}

LogOpts is log configuration struct

type MailEntity

type MailEntity struct {
	MainHost  string              `yaml:"mainHost"`
	MailFrom  string              `yaml:"mailFrom"`  // 哨兵、发送邮件账号
	MailPwd   string              `yaml:"mailPwd"`   // 发送邮件密码
	MailPort  int                 `yaml:"mailPort"`  // 发送邮件端口
	MailGroup map[string][]string `yaml:"mailGroup"` // 邮件组
	*Log
}

func NewMail

func NewMail(v *viper.Viper, logger *zap.Logger) *MailEntity

func (*MailEntity) GetMailGroup

func (this *MailEntity) GetMailGroup(key string) (result []string)

GetMailGroup 获取邮件组下所有邮箱 all 返回所有, map[] 不可以设置 all

func (*MailEntity) Send

func (this *MailEntity) Send(ctx context.Context, to []string, title string, content string) (err error)

type RedisOpt

type RedisOpt struct {
	Addr     string `yaml:"addr"`
	User     string `yaml:"user"` // user 没有account 可不填写
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
	PoolSize int    `yaml:"poolSize"`
}

Directories

Path Synopsis
Package crypt2go @file : crypt2go.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:45 @Description:
Package crypt2go @file : crypt2go.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:45 @Description:
ecb
Package ecb @file : ecb.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:45 @Description:
Package ecb @file : ecb.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:45 @Description:
padding
Package padding @file : padding.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:47 @Description:
Package padding @file : padding.go @author : china.gdxs@gmail.com @time : 2024/2/3 16:47 @Description:

Jump to

Keyboard shortcuts

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