Documentation ¶
Index ¶
- Constants
- Variables
- func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Zap() (logger *zap.Logger)
- type BoolResult
- type Config
- type DefaultLogger
- type LockContext
- type LockOperator
- type Locker
- type LogLevel
- type Logger
- type RedisClientAdapter
- type RedisLock
- type RedisLockOperator
- func (operator *RedisLockOperator) GetLock(key string, config Config) (lock Locker, err error)
- func (operator *RedisLockOperator) Lock(key string, ctx LockContext) error
- func (operator *RedisLockOperator) TryLock(key string, ctx LockContext, timeout time.Duration) error
- func (operator *RedisLockOperator) Unlock(key string) (bool, error)
- type RedisOps
- type Result
- type StringResult
Constants ¶
View Source
const ( Error = iota + 1 Warn Info Debug )
Variables ¶
Functions ¶
func CustomTimeEncoder ¶
func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
自定义日志输出时间格式
Types ¶
type BoolResult ¶
type BoolResult struct {
Result
}
func (*BoolResult) BoolVal ¶
func (r *BoolResult) BoolVal() bool
type DefaultLogger ¶
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(msg string, data ...interface{})
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(msg string, data ...interface{})
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(msg string, data ...interface{})
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(msg string, data ...interface{})
type LockContext ¶
LockContext goroutine lock context
func Context ¶
func Context() LockContext
Context Obtain the goroutine lock context, which is required when locking. When using reentrant locks, the context of multiple locking must be the same.
type LockOperator ¶
type Locker ¶
type Locker interface { Lock(ctx LockContext) error TryLock(ctx LockContext, time time.Duration) error //Attempt to lock for a fixed duration Unlock() (bool, error) }
type RedisClientAdapter ¶
type RedisClientAdapter interface { RedisOps }
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
RedisLock Redis distributed lock structure, implementing Locker interface
func NewRedisLock ¶
func NewRedisLock(lockKey string, redisClient RedisClientAdapter, config *Config) (*RedisLock, error)
NewRedisLock lockKey and redisClient are required parameters, and options are optional parameters.
func (*RedisLock) Lock ¶
func (r *RedisLock) Lock(ctx LockContext) error
Lock ctx is the context of the current goroutine, which can be obtained through Context()
type RedisLockOperator ¶
type RedisLockOperator struct {
// contains filtered or unexported fields
}
func NewRedisLockOperator ¶
func NewRedisLockOperator(client RedisClientAdapter, config Config) (*RedisLockOperator, error)
func (*RedisLockOperator) GetLock ¶
func (operator *RedisLockOperator) GetLock(key string, config Config) (lock Locker, err error)
GetLock Get the lock object from locks and return it. If it does not exist, first create the lock object according to the key, then save the lock object to locks, and finally return the lock object.
func (*RedisLockOperator) Lock ¶
func (operator *RedisLockOperator) Lock(key string, ctx LockContext) error
func (*RedisLockOperator) TryLock ¶
func (operator *RedisLockOperator) TryLock(key string, ctx LockContext, timeout time.Duration) error
type StringResult ¶
type StringResult struct {
Result
}
func (*StringResult) StringVal ¶
func (r *StringResult) StringVal() string
Click to show internal directories.
Click to hide internal directories.