utils

package
v0.0.0-...-7232a66 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)

Functions

func CamelString

func CamelString(name string) string

*

  • 蛇形转驼峰
  • @description xx_yy to XxYx xx_y_y to XxYY
  • 转换为大驼峰命名法则
  • 首字母大写,“_” 忽略后大写

func CreateDir

func CreateDir(dirs ...string) (err error)

func CustomTimeEncoder

func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

自定义日志输出时间格式

func GetWriteSyncer

func GetWriteSyncer(file string) zapcore.WriteSyncer

func PasswordHash

func PasswordHash(pwd string) (string, error)

* hash 加密密码 * @param string pwd 待加密的明文密码

func PasswordVerify

func PasswordVerify(hashedPwd string, sourcePwd string) bool

* 验证 hash 密码 * @param string hashedPwd 已加密的hash密码 * @param string sourcePwd 确认密码

func PathExists

func PathExists(path string) (bool, error)

func SnakeString

func SnakeString(name string) string

*

  • 驼峰转蛇形 snake string
  • @description XxYy to xx_yy , XxYY to xx_y_y
  • @date 2020/7/30
  • @param s 需要转换的字符串
  • @return string *

func Struct2ColumnsValues

func Struct2ColumnsValues(model interface{}, tag string) (columns []string, values []interface{})

func Struct2Map

func Struct2Map(in interface{}, tagName string) (map[string]interface{}, error)

ToMap 结构体转为Map[string]interface{}

func Struct2Slice

func Struct2Slice(f interface{}) []string

func Task

func Task(f TaskFunc, cb func(), params ...interface{})

func Viper

func Viper(path ...string) *viper.Viper

func Zap

func Zap() (logger *zap.Logger)

Types

type JSON

type JSON []byte

func StructToJSON

func StructToJSON(value interface{}) JSON

func (JSON) Equals

func (j JSON) Equals(j1 JSON) bool

func (JSON) IsNull

func (j JSON) IsNull() bool

func (JSON) MarshalJSON

func (m JSON) MarshalJSON() ([]byte, error)

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

func (*JSON) UnmarshalJSON

func (m *JSON) UnmarshalJSON(data []byte) error

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

type JSONTime

type JSONTime time.Time

JSONTime 自定义时间

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

func (*JSONTime) String

func (t *JSONTime) String() string

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) error

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(session jwtService.Session) jwtService.CustomSession

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims jwtService.CustomSession) (string, error)

创建一个token

func (*JWT) CreateTokenByOldToken

func (j *JWT) CreateTokenByOldToken(oldToken string, claims jwtService.CustomSession) (string, error)

CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*jwtService.CustomSession, error)

解析 token

type Locker

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

func NewLocker

func NewLocker(key string) *Locker

func NewLockerWithTTL

func NewLockerWithTTL(key string, expire time.Duration) *Locker

有过期时间

func (*Locker) Lock

func (l *Locker) Lock() *Locker

func (*Locker) Unlock

func (l *Locker) Unlock()

type TaskExecutor

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

func NewTaskExecutor

func NewTaskExecutor(f TaskFunc, p []interface{}, callback func()) *TaskExecutor

func (*TaskExecutor) Exec

func (t *TaskExecutor) Exec()

type TaskFunc

type TaskFunc func(params ...interface{})

Jump to

Keyboard shortcuts

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