Documentation
¶
Index ¶
- Constants
- Variables
- func BigCamels(sep byte, data string) string
- func Black(format string, args ...interface{})
- func Blue(format string, args ...interface{})
- func Bytes2Float64(data []byte) float64
- func Bytes2Int64(data []byte) int64
- func Bytes2String(data []byte) string
- func CreatePkcs1Keys(keyLength int) (privateKey, publicKey string)
- func CreatePkcs8Keys(keyLength int) (privateKey, publicKey string)
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func FileExists(fileName string) bool
- func Fuchsia(format string, args ...interface{})
- func Green(format string, args ...interface{})
- func HMac(key []byte, data []byte, hash crypto.Hash) string
- func Hash(data []byte, hash crypto.Hash) string
- func HashValue(key interface{}) uint32
- func Index4Bit(key interface{}, bitCount uint8) uint32
- func Index4Int16(key interface{}) int16
- func Index4Int8(key interface{}) int8
- func Index4Uint8(key interface{}) uint8
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func InitLogger(l Logger)
- func InitZap(l *zap.Logger)
- func InitZapWithConfig(conf zap.Config, opts ...zap.Option) error
- func InitZapWithCore(core zapcore.Core, opts ...zap.Option)
- func InitZapWithProduction(opts ...zap.Option) error
- func Ip2Long(ip string) (ipVal uint32, err error)
- func JsonDecode(data []byte, v interface{}) (err error)
- func JsonDecodeFile(filePath string, v interface{}) (err error)
- func JsonEncode(v interface{}) (data []byte, err error)
- func LocalIp() (ip string, err error)
- func Long2Ip(ipVal uint32) string
- func MarshalPkcs8PrivateKey(key *rsa.PrivateKey) []byte
- func Md5(data []byte) string
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Red(format string, args ...interface{})
- func RedFatal(format string, args ...interface{})
- func Sha1(data []byte) string
- func SmallCamels(sep byte, data string) string
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
- func YamlDecode(data []byte, v interface{}) (err error)
- func YamlDecodeFile(filePath string, v interface{}) (err error)
- func YamlEncode(v interface{}) (data []byte, err error)
- func Yellow(format string, args ...interface{})
- func ZapDebug(msg string, fields ...zap.Field)
- func ZapError(msg string, fields ...zap.Field)
- func ZapFatal(msg string, fields ...zap.Field)
- func ZapInfo(msg string, fields ...zap.Field)
- func ZapPanic(msg string, fields ...zap.Field)
- func ZapSync() error
- func ZapWarn(msg string, fields ...zap.Field)
- type Aes
- type Bitmap
- type CanHash
- type GetMachineId
- type HashRing
- type HashSet
- type I18n
- type Logger
- type Msg
- type Node
- type NodeList
- type Rsa
- type ShardMap
- type SnowFlake
Constants ¶
const ( En = `en` ZhTw = `zh-tw` ZhCn = `zh_CN` )
const ( ModeWait = 1 ModeMaxTime = 2 ModeError = 3 )
Variables ¶
var ( ErrInvalidPaddingChar = errors.New(`invalid padding char`) ErrAesDecrypt = errors.New(`aes decrypt error`) )
var ( ErrMsgMapEmpty = errors.New("msgMap can not empty") ErrNoYamlFiles = errors.New("there are no `.yml` or `.yaml` files in this directory") ErrNoJsonFiles = errors.New("there are no `.json` files in this directory") )
var ( ErrIpV4Address = errors.New(`invalid ip v4 address`) ErrNotFoundIp = errors.New("not found ip address") )
var ( // AcquireArgs 获取参数 AcquireArgs = func() []interface{} { return argsPool.Get().([]interface{}) } // ReleaseArgs 释放参数 ReleaseArgs = func(args *[]interface{}) { if args == nil { return } *args = (*args)[:0] argsPool.Put(*args) } )
var ( ErrOutOfRange = errors.New("out of range") ErrTimeBack = errors.New("time go back") ErrMachineId = errors.New("illegal machine id") ErrLogicId = errors.New("illegal logic id") )
var ErrNoServer = errors.New("no server")
var (
SetValue = struct{}{}
)
Functions ¶
func Bytes2Float64 ¶ added in v1.0.12
Bytes2Float64 字节切片转换为float64
func CreatePkcs1Keys ¶ added in v1.0.6
CreatePkcs1Keys 生成pkcs1格式公钥私钥
func CreatePkcs8Keys ¶ added in v1.0.3
CreatePkcs8Keys 生成pkcs8格式公钥私钥
func InitLogger ¶ added in v1.0.21
func InitLogger(l Logger)
func InitZapWithConfig ¶ added in v1.0.21
InitZapWithConfig with zap.Config初始化Zap日志
func InitZapWithCore ¶ added in v1.0.21
InitZapWithCore with core初始化Zap日志
func InitZapWithProduction ¶ added in v1.0.21
InitZapWithProduction with production初始化Zap日志
func JsonDecodeFile ¶
JsonDecodeFile ---
func MarshalPkcs8PrivateKey ¶ added in v1.0.6
func MarshalPkcs8PrivateKey(key *rsa.PrivateKey) []byte
func SmallCamels ¶ added in v1.0.20
SmallCamels 转换为小驼峰
func YamlDecodeFile ¶
YamlDecodeFile ---
Types ¶
type Aes ¶ added in v1.0.3
type Aes struct {
// contains filtered or unexported fields
}
Aes Aes加密
func (*Aes) CbcDecrypt ¶ added in v1.0.3
CbcDecrypt cbc解密
func (*Aes) CbcEncrypt ¶ added in v1.0.3
CbcEncrypt cbc加密
type Bitmap ¶
type Bitmap interface {
// HasBit 是否有值
HasBit() bool
// BitCount 值的数量
BitCount() int
// Exists 标签是否存在
Exists(tag int) (exists bool)
// AddTag 添加标签
AddTag(tag int) Bitmap
// DelTag 删除标签
DelTag(tag int) Bitmap
// Data 原始数据
Data() (data []byte)
// SprinfBinary 二进制打印
SprinfBinary() string
}
Bitmap bitmap数据结构
type CanHash ¶
type CanHash interface {
// HashCode 计算hash值
HashCode() (hashValue uint32)
}
CanHash hash接口
type GetMachineId ¶ added in v1.0.8
GetMachineId 获取机器Id
func GetMachineIdByEnv ¶ added in v1.0.8
func GetMachineIdByEnv(key string) GetMachineId
GetMachineIdByEnv 根据环境变量获取机器Id
func GetMachineIdByIp ¶ added in v1.0.8
func GetMachineIdByIp() GetMachineId
GetMachineIdByIp 根据Ip获取机器Id
type HashRing ¶ added in v1.0.9
type HashRing interface {
// Store 存储servers
Store(servers ...CanHash)
// Get 获取server
Get(key interface{}) (server CanHash, err error)
// Index 根据index获取server
Index(index int) (server CanHash, err error)
// Add 添加server
Add(server CanHash)
// Remove 移除server
Remove(server CanHash)
// Length 获取servers长度
Length() int
// Range 遍历servers
Range(handler func(index int, server CanHash, hitCount uint64) (handled bool))
}
HashRing Hash环
func NewHashRing ¶ added in v1.0.9
type HashSet ¶
type HashSet interface {
// Add 添加元素
Add(items ...interface{}) (newNum int)
// Delete 删除元素
Delete(items ...interface{}) (delNum int)
// Exists 元素是否存在
Exists(item interface{}) (exists bool)
// Length 长度
Length() (length int)
}
HashSet 接口
type I18n ¶ added in v1.0.3
I18n 多语言接口
func NewI18nFromJson ¶ added in v1.0.3
NewI18nFromJson 从Json文件配置实例化多语言
type Logger ¶ added in v1.0.21
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
Panic(args ...interface{})
Fatal(args ...interface{})
Debugf(template string, args ...interface{})
Infof(template string, args ...interface{})
Warnf(template string, args ...interface{})
Errorf(template string, args ...interface{})
Panicf(template string, args ...interface{})
Fatalf(template string, args ...interface{})
}
Logger 日志接口
type Rsa ¶ added in v1.0.3
type Rsa struct {
// contains filtered or unexported fields
}
Rsa Rsa
func NewRsaWithPkcs1 ¶ added in v1.0.6
NewRsaWithPkcs1 pkcs1实例化Rsa
func NewRsaWithPkcs8 ¶ added in v1.0.6
NewRsaWithPkcs8 pkcs8实例化Rsa
type ShardMap ¶
type ShardMap interface {
// Set 存储
Set(key interface{}, value interface{}) (isCreate bool)
// Get 获取
Get(key interface{}) (value interface{}, exists bool)
// Exists 是否存在
Exists(key interface{}) (exists bool)
// Delete 删除
Delete(keys ...interface{}) (delNum int)
// Length 长度
Length() int64
}
ShardMap 分片Map
func NewSharMapWithChannel ¶ added in v1.1.0
func NewSharMapWithChannel(size int) (sm ShardMap, ch <-chan shardmap.ChangeEvent)
NewSharMapWithChannel 实例化ShardMap并返回changeChannel
type SnowFlake ¶ added in v1.0.8
type SnowFlake interface {
// Id 生成id
Id(logicId uint8) (int64, error)
// ZapInfo 根据id获取信息
Info(id int64) (timestamp int64, machineId uint8, logicId uint8, index int16)
}
SnowFlake 雪花算法接口,1位0,41位毫秒时间戳,8位机器码,2位业务码,12位递增值
func NewSFByMachineFunc ¶ added in v1.0.8
func NewSFByMachineFunc(mode uint8, machindFunc GetMachineId, timeStampBegin int64) (sfl SnowFlake, err error)
NewSFByMachineFunc GetMachineId方式实例化雪花算法