utils

package
v0.0.0-...-2cd7638 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseRedisCli

func CloseRedisCli()

func DeleteCacheFromRedisMessage

func DeleteCacheFromRedisMessage(msg *redis.Message)

DeleteCacheFromRedisMessage 根据redis订阅消息清空内存缓存

func GetCacheCli

func GetCacheCli() *cache.Cache

func GetInternetAddress

func GetInternetAddress() (ip string, err error)

GetInternetAddress 获取网络IP

func GetRedisCli

func GetRedisCli() *redis.Client

func GetRedisSubPool

func GetRedisSubPool() *redisSubscriptionPool

GetRedisSubPool 获取redis订阅连接池

func Go

func Go(f func())

Go 统一的 goroutine 创建,避免因为 panic 导致主进程退出

func GoWithGroup

func GoWithGroup(f func() error) (func() error, context.Context)

GoWithGroup 使用 errgroup 创建 goroutine

func InitDefaultLog

func InitDefaultLog()

InitDefaultLog 初始化一个默认的日志实例

func InitLog

func InitLog(opts *LoggerOptions)

InitLog 初始化日志结构体 Logger 与 SugarLogger

func PingRedis

func PingRedis(ctx context.Context) (string, bool)

func RegisteDeleteCache

func RegisteDeleteCache(channel string)

RegisteDeleteCache 从redis中订阅清空内存缓存 假如订阅事件已存在,则什么都不做 异步注册,避免获取订阅连接时影响业务逻辑性能

Types

type LoggerOptions

type LoggerOptions struct {
	// OutToFile 是否将日志记录到文件
	OutToFile bool
	// LogHome 日志文件设定的目录,当 OutToFile 为true时生效
	LogHome string
	// LogLevel 应用日志等级,低于该日志等级的将不会被输出
	LogLevel zapcore.Level
}

type LoggerWrapper

type LoggerWrapper struct {
	// 日志结构体,可以输出 结构化日志
	*zap.Logger
	// sugarLogger 日志结构体,可以输出 结构化日志、非结构化日志
	S *zap.SugaredLogger
	// contains filtered or unexported fields
}

func GetLogger

func GetLogger() *LoggerWrapper

GetLogger 获取日志实例

func (LoggerWrapper) GetErrorWriter

func (l LoggerWrapper) GetErrorWriter() io.Writer

func (LoggerWrapper) GetWriter

func (l LoggerWrapper) GetWriter() io.Writer

func (*LoggerWrapper) SyncAndClose

func (l *LoggerWrapper) SyncAndClose() (err error)

SyncAndClose 刷新 logger 缓冲区,并关闭写入对象

type StringSet

type StringSet map[string]struct{}

func NewSet

func NewSet(arr ...string) *StringSet

NewSet 根据不定长字符串生成一个set结构的数据集合

func NewSetFromSlice

func NewSetFromSlice(arr []string) *StringSet

NewSetFromSlice 根据数组生成一个set结构的数据集合 即使数组长度为空也会返回一个可用的空集合

func (StringSet) Has

func (s StringSet) Has(str string) (ok bool)

Has 是否存在元素

func (StringSet) Intersection

func (s StringSet) Intersection(arr []string) bool

Intersection 与传入字符串数组是否存在交集

func (StringSet) IsEmpty

func (s StringSet) IsEmpty() bool

IsEmpty 是否为空

func (*StringSet) MarshalJSON

func (s *StringSet) MarshalJSON() (bs []byte, err error)

MarshalJSON 将set集合序列化为array结构的Json数据

func (*StringSet) UnmarshalJSON

func (s *StringSet) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON 将array结构的Json数据反序列化为set结构

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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