Documentation
¶
Index ¶
- Constants
- Variables
- func BigCamels(sep byte, data string) string
- func BinPath() 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 Bytes2Uint32(data []byte) uint32
- func CreatePkcs1Keys(keyLength int) (privateKey, publicKey string)
- func CreatePkcs8Keys(keyLength int) (privateKey, publicKey string)
- func DPanic(msg string, fields ...zap.Field)
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- 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 Hex2Int64(value string) int64
- func Hex2Uint64(value string) uint64
- func Index4Bit(key interface{}, bitCount uint8) uint32
- func Index4Int16(key interface{}) int16
- func Index4Int8(key interface{}) int8
- func Index4Uint8(key interface{}) uint8
- func Info(msg string, fields ...zap.Field)
- func InitZapWithOption(conf zaplogger.Option, zapOpts ...zap.Option) error
- func Int64ToHex(value int64) string
- func Int64ToHexWithPad(value int64, padLength int) string
- func Ip2Long(ip string) (ipVal uint32, err error)
- func IsLevel(level zapcore.Level) bool
- func JsonDecode(data string, v interface{}) (err error)
- func JsonDecodeFile(filePath string, v interface{}) (err error)
- func JsonEncode(v interface{}) (data string, 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 NewGoPool(size int, opts ...gopool.Option) (*gopool.Pool, error)
- func Panic(msg string, fields ...zap.Field)
- func PprofIsRun() bool
- func RandBytes(length int) []byte
- 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 StartPprof(addr string, handler http.Handler) error
- func StopPprof(ctx context.Context) error
- func ToString(val interface{}) string
- func Uint64ToHex(value uint64) string
- func Warn(msg string, fields ...zap.Field)
- func YamlDecode(data string, v interface{}) (err error)
- func YamlDecodeFile(filePath string, v interface{}) (err error)
- func YamlEncode(v interface{}) (data string, err error)
- func Yellow(format string, args ...interface{})
- func ZapDPanic(msg string, fields ...zap.Field)
- 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 Accept
- type Aes
- type Bitmap
- type CanHash
- type Config
- type Container
- type Context
- func (c *Context) Abort()
- func (c *Context) Close()
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetBool(key string) (value bool, exists bool)
- func (c *Context) GetInt(key string) (value int, exists bool)
- func (c *Context) GetInt64(key string) (value int64, exists bool)
- func (c *Context) GetInt8(key string) (value int8, exists bool)
- func (c *Context) GetString(key string) (value string, exists bool)
- func (c *Context) IsAborted() bool
- func (c *Context) Next()
- func (c *Context) Set(key string, value interface{})
- func (c *Context) Value(key interface{}) interface{}
- type GetMachineId
- type HashRing
- type HashSet
- type I18n
- type JsonParam
- func (jp JsonParam) Exists(key string) bool
- func (jp JsonParam) Float64(key string) float64
- func (jp JsonParam) Int(key string) int
- func (jp JsonParam) Int64(key string) int64
- func (jp JsonParam) Int64Slice(key string) []int64
- func (jp JsonParam) IntSlice(key string) []int
- func (jp JsonParam) JsonMarshal() []byte
- func (jp JsonParam) String(key string) string
- func (jp JsonParam) StringSlice(key string) []string
- func (jp JsonParam) Uint32Slice(key string) []uint32
- type Node
- type NodeList
- type Package
- type Protocol
- type Rsa
- type ShardMap
- type SnowFlake
- type Status
- func (s *Status) Close()
- func (s *Status) ConvertGrpcStatus(details ...proto.Message) (*status.Status, error)
- func (s *Status) Error() error
- func (s *Status) Is(code codes.Code) bool
- func (s *Status) IsOK() bool
- func (s *Status) JsonMarshal() []byte
- func (s *Status) WithData(data interface{}) *Status
- func (s *Status) WithMsg(msg string) *Status
Constants ¶
const ( LevelJson = 0 LevelV1 = 1 LevelV2 = 2 )
const ( // OK 成功返回 OK = codes.OK // ErrCanceled 表示操作已取消(通常由调用者取消) ErrCanceled = codes.Canceled // ErrUnknown 未知错误 ErrUnknown = codes.Unknown // ErrInvalidArgument 客户端传递了一个无效的参数 ErrInvalidArgument = codes.InvalidArgument // ErrDeadlineExceeded 表示操作在完成前过期。对于改变系统状态的操作,即使操作成功完成,也可能会返回此错误。 // 例如,来自服务器的成功响应可能已延迟足够长的时间以使截止日期到期 ErrDeadlineExceeded = codes.DeadlineExceeded // ErrNotFound 表示未找到某些请求的实体(例如文件或目录) ErrNotFound = codes.NotFound // ErrAlreadyExists 表示创建实体的尝试失败,因为实体已经存在 ErrAlreadyExists = codes.AlreadyExists // ErrPermissionDenied 表示调用者没有执行指定操作的权限 ErrPermissionDenied = codes.PermissionDenied // ErrResourceExhausted 表示某些资源已用尽,可能是每个用户的配额,或者可能是整个文件系统空间不足 ErrResourceExhausted = codes.ResourceExhausted // ErrFailedPrecondition 操作被拒绝,因为系统未处于操作执行所需的状态。 // 例如,要删除的目录可能是非空的,rmdir 操作应用于非目录等 ErrFailedPrecondition = codes.FailedPrecondition // ErrAborted 操作已取消,通常是由于并发问题,如排序器检查失败、事务中止 ErrAborted = codes.Aborted // ErrOutRange 超出范围的操作 ErrOutRange = codes.OutOfRange // ErrUnimplemented 未实现或不支持的操作 ErrUnimplemented = codes.Unimplemented // ErrInternal 系统内部错误 ErrInternal = codes.Internal // 请注意,重试非幂等操作是不安全的 ErrUnavailable = codes.Unavailable // ErrDataLoss 表示不可恢复的数据丢失或损坏 ErrDataLoss = codes.DataLoss // ErrUnauthenticated 表示请求没有用于操作的有效身份验证凭据 ErrUnauthenticated = codes.Unauthenticated )
const ( EnvPro = `pro` EnvDev = `dev` EnvTest = `test` )
const ( ConnectSuccess = 0x0100 Tick = 0x0101 Login = 0x0200 LoginSuccess = 0x0201 LoginFailed = 0x0202 )
const ( ModeWait = 1 ModeMaxTime = 2 ModeError = 3 )
const (
ZhCn = `zh_CN`
)
Variables ¶
var ( ErrInvalidPaddingChar = errors.New(`invalid padding char`) ErrAesDecrypt = errors.New(`aes decrypt error`) )
var ( ErrForbidden = errors.New("forbidden") ErrDataEmpty = errors.New("data is empty") ErrKeyFormat = errors.New("invalid key format") ErrDataFormat = errors.New("invalid data format") ErrDataSign = errors.New("invalid data sign") )
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 ( JsonMarshal = jsoniter.Marshal JsonUnmarshal = jsoniter.Unmarshal )
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 ( YamlMarshal = yaml.Marshal YamlUnmarshal = yaml.Unmarshal )
var (
DefaultContainer = &Container{}
)
var ErrNoServer = errors.New("no server")
var (
SetValue = struct{}{}
)
Functions ¶
func Bytes2Float64 ¶ added in v1.0.12
Bytes2Float64 字节切片转换为float64
func Bytes2Uint32 ¶ added in v1.2.5
Bytes2Uint32 字节切片转换为uint32
func CreatePkcs1Keys ¶ added in v1.0.6
CreatePkcs1Keys 生成pkcs1格式公钥私钥
func CreatePkcs8Keys ¶ added in v1.0.3
CreatePkcs8Keys 生成pkcs8格式公钥私钥
func InitZapWithOption ¶ added in v1.2.5
func Int64ToHexWithPad ¶ added in v1.2.6
Int64ToHexWithPad _
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 StartPprof ¶ added in v1.2.6
StartPprof _
func YamlDecodeFile ¶
YamlDecodeFile ---
Types ¶
type Accept ¶ added in v1.2.7
type Accept struct {
// contains filtered or unexported fields
}
func (*Accept) AcceptBase64Url ¶ added in v1.2.7
type Aes ¶ added in v1.0.3
type Aes struct {
// contains filtered or unexported fields
}
Aes Aes加密
func NewAesWithBytes ¶ added in v1.1.4
NewAesWithBytes 实例化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 Config ¶ added in v1.2.5
type Config struct {
Name string `json:"name" yaml:"name"`
Addr string `json:"addr" yaml:"addr"`
PprofAddr string `json:"pprofAddr" yaml:"pprofAddr"`
Env string `json:"env" yaml:"env"`
Ver string `json:"ver" yaml:"ver"`
Logger zaplogger.Option `json:"logger" yaml:"logger"`
Params JsonParam `json:"params" yaml:"params"`
}
type Container ¶ added in v1.2.5
type Container struct {
// contains filtered or unexported fields
}
type Context ¶ added in v1.1.3
type Context struct {
// contains filtered or unexported fields
}
Context 上下文
func AcquireCtx ¶ added in v1.1.3
AcquireCtx 申请Context
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 JsonParam ¶ added in v1.2.1
type JsonParam map[string]interface{}
func UnmarshalJsonParam ¶ added in v1.2.1
UnmarshalJsonParam _
func (JsonParam) Int64Slice ¶ added in v1.2.1
Int64Slice 获取[]int64,获取失败返回nil
func (JsonParam) JsonMarshal ¶ added in v1.2.1
JsonMarshal _
func (JsonParam) StringSlice ¶ added in v1.2.1
StringSlice 获取[]string,如果不是[]string返回nil
func (JsonParam) Uint32Slice ¶ added in v1.2.1
Uint32Slice 获取[]uint32,获取失败返回nil
type Package ¶ added in v1.2.6
type Protocol ¶ added in v1.2.7
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)
// IdTime 根据指定时间生成id
IdTime(current time.Time, logicId uint8) (int64, error)
// Info 根据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方式实例化雪花算法
type Status ¶ added in v1.2.3
type Status struct {
Code codes.Code `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
func StatusWithCode ¶ added in v1.2.3
StatusWithCode 指定Code获取一个Status
func StatusWithJsonUnmarshal ¶ added in v1.2.3
StatusWithJsonUnmarshal 指定json []byte获取一个Status
func (*Status) ConvertGrpcStatus ¶ added in v1.2.3
ConvertGrpcStatus 转换为grpc状态码