Documentation ¶
Index ¶
- Variables
- func BytesMD5Hash(data []byte) string
- func CORSMiddleware(origin string) gin.HandlerFunc
- func CacheInRedisMiddleware(cacheUrlTags []string) gin.HandlerFunc
- func CleanCacheInRedis(tag string) error
- func CreateJWTToken(claims CustomJWTClaims, salt []byte) (string, error)
- func DatetimeStr2Timestamp(datetime string) (int64, error)
- func FlowLimitMiddleware(secToken rate.Limit, maxToken int) gin.HandlerFunc
- func InitRedisClient(addr, password string, db int)
- func LoadCacheInRedis(c *gin.Context) ([]byte, error)
- func MultiStringMD5Hash(data ...string) string
- func NowDatetimeStr() string
- func NowTimestamp() int64
- func RefreshJWTToken(tokenStr string, salt []byte, survivalTime time.Duration) (string, error)
- func SafeSliceString(data string, start, end int) (string, error)
- func SetCORSHeaders(header http.Header, allowOrigin string)
- func StorageCacheInRedis(c *gin.Context, body gin.H, expire time.Duration) ([]byte, error)
- func StringContainsHan(data string) bool
- func StringContainsSpace(data string) bool
- func StringMD5Hash(data string) string
- func Timestamp2DatetimeStr(timestamp int64) string
- func TodayDateStr() string
- type CustomJWTClaims
- type GinStyleLogger
- type RotateFileWriter
Constants ¶
This section is empty.
Variables ¶
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:") )
Error notes
var ErrIndexOutOfRange = errors.New("the 'start' or 'end' index value is out of range")
var ErrStartLargeThenEnd = errors.New("the 'start' index value is over then 'end'")
var ErrTokenNumber = errors.New("secToken的值必须小于等于maxToken的值")
var ErrTooManyRequests = errors.New(http.StatusText(429))
Functions ¶
func CacheInRedisMiddleware ¶
func CacheInRedisMiddleware(cacheUrlTags []string) gin.HandlerFunc
缓存读取中间件
func CreateJWTToken ¶
func CreateJWTToken(claims CustomJWTClaims, salt []byte) (string, error)
生成JWT TOKEN: claims 载体数据, salt加密盐值
func DatetimeStr2Timestamp ¶
Parse a datetime string into unix timestamp, unit:sec
func FlowLimitMiddleware ¶
func FlowLimitMiddleware(secToken rate.Limit, maxToken int) gin.HandlerFunc
限流中间件 每秒产生secToken个令牌, 最多存放maxToken个令牌, 即一秒内最多允许maxToken个请求
func InitRedisClient ¶
初始化RedisClient, 在程序启动阶段的代码中去执行
func MultiStringMD5Hash ¶
Get the MD5 hash value of multi string
func RefreshJWTToken ¶
刷新JWT TOKEN tokenStr TOKEN字符串, salt加密盐值, survivalTime存活时间
func SafeSliceString ¶
安全的切割字符串: data原字符串, start切片起点, end切片终点+1 Direct cutting of string may cause character scrambling, because some character could be 3 or 4 byte. Translate the 'string' into 'rune' before cutting could make safe
func SetCORSHeaders ¶
func StorageCacheInRedis ¶
存储缓存数据
func Timestamp2DatetimeStr ¶
Get the datetime string of one timestamp
Types ¶
type CustomJWTClaims ¶
type CustomJWTClaims struct { CustomData interface{} `json:"custom_data"` jwt.StandardClaims }
自定义载体, CustomData用于保存自定义的数据; jwt.StandardClaims用于存储载体附属信息, 特别是过期时间
func ParseJWTToken ¶
func ParseJWTToken(tokenStr string, salt []byte) (*CustomJWTClaims, error)
解析JWT TOKEN: tokenStr TOKEN字符串, salt加密盐值
type GinStyleLogger ¶
type GinStyleLogger struct { // Optional. Default value is gin.defaultGinStyleLogFormatter Formatter gin.LogFormatter // Output is a writer where logs are written. // Optional. Default value is gin.DefaultWriter. Output io.Writer }
Logger for output the custom log information with gin style in the gin.HandlerFunc.
func NewGinStyleLogger ¶
func NewGinStyleLogger(out io.Writer, formatter gin.LogFormatter) *GinStyleLogger
return a StyleLogger instance with the params. when the param is nil, will use the default value.
type RotateFileWriter ¶
type RotateFileWriter struct {
// contains filtered or unexported fields
}
Custom rotate file writer.
func NewRotateFileWriter ¶
func NewRotateFileWriter(fileName, dirPath string, maxCount int, maxSize int64) *RotateFileWriter
循环文件写入器: fileName基本文件名, dirPath文件夹路径, maxCount最大文件数量, maxSize最大文件体积
func (*RotateFileWriter) Init ¶
func (obj *RotateFileWriter) Init()
Initial method, check whether the log dir existed and have history log files