base

package module
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 43 Imported by: 20

README

base

base

Documentation

Index

Constants

View Source
const (
	LevelJson = 0
	LevelV1   = 1
	LevelV2   = 2
)
View Source
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 表示该服务当前不可用。这很可能是一种瞬态情况,可以通过回退重试来纠正。
	// 请注意,重试非幂等操作是不安全的
	ErrUnavailable = codes.Unavailable

	// ErrDataLoss 表示不可恢复的数据丢失或损坏
	ErrDataLoss = codes.DataLoss

	// ErrUnauthenticated 表示请求没有用于操作的有效身份验证凭据
	ErrUnauthenticated = codes.Unauthenticated
)
View Source
const (
	EnvPro  = `pro`
	EnvDev  = `dev`
	EnvTest = `test`
)
View Source
const (
	ConnectSuccess = 0x0100
	Tick           = 0x0101

	Login        = 0x0200
	LoginSuccess = 0x0201
	LoginFailed  = 0x0202
)
View Source
const (
	ModeWait    = 1
	ModeMaxTime = 2
	ModeError   = 3
)
View Source
const (
	ZhCn = `zh_CN`
)

Variables

View Source
var (
	ErrInvalidPaddingChar = errors.New(`invalid padding char`)
	ErrAesDecrypt         = errors.New(`aes decrypt error`)
)
View Source
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")
)
View Source
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")
)
View Source
var (
	ErrIpV4Address = errors.New(`invalid ip v4 address`)
	ErrNotFoundIp  = errors.New("not found ip address")
)
View Source
var (
	JsonMarshal   = jsoniter.Marshal
	JsonUnmarshal = jsoniter.Unmarshal
)
View Source
var (

	// AcquireArgs 获取参数
	AcquireArgs = func() []interface{} {
		return argsPool.Get().([]interface{})
	}

	// ReleaseArgs 释放参数
	ReleaseArgs = func(args *[]interface{}) {
		if args == nil {
			return
		}

		*args = (*args)[:0]
		argsPool.Put(*args)
	}
)
View Source
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")
)
View Source
var (
	YamlMarshal   = yaml.Marshal
	YamlUnmarshal = yaml.Unmarshal
)
View Source
var (
	DefaultContainer = &Container{}
)
View Source
var ErrNoServer = errors.New("no server")
View Source
var (
	SetValue = struct{}{}
)

Functions

func BigCamels added in v1.0.20

func BigCamels(sep byte, data string) string

BigCamels 转换为大驼峰

func BinPath added in v1.1.5

func BinPath() string

BinPath 获取Bin目录

func Black added in v1.0.3

func Black(format string, args ...interface{})

Black 默认输出

func Blue added in v1.0.3

func Blue(format string, args ...interface{})

Blue 颜色输出

func Bytes2Float64 added in v1.0.12

func Bytes2Float64(data []byte) float64

Bytes2Float64 字节切片转换为float64

func Bytes2Int64 added in v1.0.7

func Bytes2Int64(data []byte) int64

Bytes2Int64 字节切片转换为int64

func Bytes2String added in v1.0.7

func Bytes2String(data []byte) string

Bytes2String 字节切片转换为字符串

func Bytes2Uint32 added in v1.2.5

func Bytes2Uint32(data []byte) uint32

Bytes2Uint32 字节切片转换为uint32

func CreatePkcs1Keys added in v1.0.6

func CreatePkcs1Keys(keyLength int) (privateKey, publicKey string)

CreatePkcs1Keys 生成pkcs1格式公钥私钥

func CreatePkcs8Keys added in v1.0.3

func CreatePkcs8Keys(keyLength int) (privateKey, publicKey string)

CreatePkcs8Keys 生成pkcs8格式公钥私钥

func DPanic added in v1.2.5

func DPanic(msg string, fields ...zap.Field)

func Debug added in v1.0.21

func Debug(msg string, fields ...zap.Field)

func Error added in v1.0.21

func Error(msg string, fields ...zap.Field)

func Fatal added in v1.0.21

func Fatal(msg string, fields ...zap.Field)

func FileExists added in v1.0.22

func FileExists(fileName string) bool

FileExists 判断文件是否存在

func Fuchsia added in v1.0.3

func Fuchsia(format string, args ...interface{})

Fuchsia 颜色输出

func Green added in v1.0.3

func Green(format string, args ...interface{})

Green 成功输出

func HMac added in v1.0.3

func HMac(key []byte, data []byte, hash crypto.Hash) string

HMac HMac算法

func Hash added in v1.0.3

func Hash(data []byte, hash crypto.Hash) string

Hash Hash算法

func HashValue

func HashValue(key interface{}) uint32

HashValue 计算任意类型hash值

func Hex2Int64 added in v1.2.6

func Hex2Int64(value string) int64

Hex2Int64 _

func Hex2Uint64 added in v1.2.7

func Hex2Uint64(value string) uint64

Hex2Uint64 _

func Index4Bit

func Index4Bit(key interface{}, bitCount uint8) uint32

Index4Bit 索引路由方法,值范围为uint32

func Index4Int16

func Index4Int16(key interface{}) int16

Index4Int16 索引路由方法,值范围为int16

func Index4Int8

func Index4Int8(key interface{}) int8

Index4Int8 索引路由方法,值范围为int8

func Index4Uint8

func Index4Uint8(key interface{}) uint8

Index4Uint8 索引路由方法,值范围为uint8

func Info added in v1.0.21

func Info(msg string, fields ...zap.Field)

func InitZapWithOption added in v1.2.5

func InitZapWithOption(conf zaplogger.Option, zapOpts ...zap.Option) error

func Int64ToHex added in v1.2.6

func Int64ToHex(value int64) string

Int64ToHex _

func Int64ToHexWithPad added in v1.2.6

func Int64ToHexWithPad(value int64, padLength int) string

Int64ToHexWithPad _

func Ip2Long

func Ip2Long(ip string) (ipVal uint32, err error)

Ip2Long Ip转换为uint32

func IsLevel added in v1.2.5

func IsLevel(level zapcore.Level) bool

func JsonDecode

func JsonDecode(data string, v interface{}) (err error)

JsonDecode ---

func JsonDecodeFile

func JsonDecodeFile(filePath string, v interface{}) (err error)

JsonDecodeFile ---

func JsonEncode

func JsonEncode(v interface{}) (data string, err error)

JsonEncode ---

func LocalIp added in v1.0.8

func LocalIp() (ip string, err error)

LocalIp 获取本机Ip

func Long2Ip

func Long2Ip(ipVal uint32) string

Long2Ip uint32转换为Ip

func MarshalPkcs8PrivateKey added in v1.0.6

func MarshalPkcs8PrivateKey(key *rsa.PrivateKey) []byte

func Md5 added in v1.0.3

func Md5(data []byte) string

Md5 Md5算法

func NewGoPool added in v1.1.5

func NewGoPool(size int, opts ...gopool.Option) (*gopool.Pool, error)

NewGoPool 实例化goroutine池

func PackIn32 added in v1.2.11

func PackIn32(value int32) []byte

func PackUin32 added in v1.2.11

func PackUin32(value uint32) []byte

func Panic added in v1.0.21

func Panic(msg string, fields ...zap.Field)

func PprofIsRun added in v1.2.6

func PprofIsRun() bool

PprofIsRun _

func RandBytes added in v1.2.7

func RandBytes(length int) []byte

func Red added in v1.0.3

func Red(format string, args ...interface{})

Red 错误输出

func RedFatal added in v1.0.8

func RedFatal(format string, args ...interface{})

RedFatal 致命错误输出

func Sha1 added in v1.0.3

func Sha1(data []byte) string

Sha1 Sha1算法

func SmallCamels added in v1.0.20

func SmallCamels(sep byte, data string) string

SmallCamels 转换为小驼峰

func StartPprof added in v1.2.6

func StartPprof(addr string, handler http.Handler) error

StartPprof _

func StopPprof added in v1.2.6

func StopPprof(ctx context.Context) error

StopPprof _

func ToString added in v1.1.5

func ToString(val interface{}) string

ToString 转为字符串类型

func Uint64ToHex added in v1.2.7

func Uint64ToHex(value uint64) string

Uint64ToHex _

func UnpackInt32 added in v1.2.11

func UnpackInt32(data []byte) (value int32, err error)

func UnpackUint32 added in v1.2.11

func UnpackUint32(data []byte) (value uint32, err error)

func Warn added in v1.0.21

func Warn(msg string, fields ...zap.Field)

func YamlDecode

func YamlDecode(data string, v interface{}) (err error)

YamlDecode ---

func YamlDecodeFile

func YamlDecodeFile(filePath string, v interface{}) (err error)

YamlDecodeFile ---

func YamlEncode

func YamlEncode(v interface{}) (data string, err error)

YamlEncode ---

func Yellow added in v1.0.3

func Yellow(format string, args ...interface{})

Yellow 警告输出

func ZapDPanic added in v1.2.5

func ZapDPanic(msg string, fields ...zap.Field)

func ZapDebug added in v1.0.21

func ZapDebug(msg string, fields ...zap.Field)

func ZapError added in v1.0.21

func ZapError(msg string, fields ...zap.Field)

func ZapFatal added in v1.0.21

func ZapFatal(msg string, fields ...zap.Field)

func ZapInfo added in v1.0.21

func ZapInfo(msg string, fields ...zap.Field)

func ZapPanic added in v1.0.21

func ZapPanic(msg string, fields ...zap.Field)

func ZapSync added in v1.0.21

func ZapSync() error

func ZapWarn added in v1.0.21

func ZapWarn(msg string, fields ...zap.Field)

Types

type Accept added in v1.2.7

type Accept struct {
	// contains filtered or unexported fields
}

func NewAccept added in v1.2.7

func NewAccept(aes *Aes, level uint8) *Accept

func (*Accept) Accept added in v1.2.7

func (a *Accept) Accept(level uint8, secretData []byte) (protocol Protocol, err error)

func (*Accept) AcceptBase64Url added in v1.2.7

func (a *Accept) AcceptBase64Url(level uint8, base64Data []byte, urlSafe bool) (protocol Protocol, err error)

func (*Accept) AcceptHex added in v1.2.7

func (a *Accept) AcceptHex(level uint8, hexData []byte) (protocol Protocol, err error)

type Aes added in v1.0.3

type Aes struct {
	// contains filtered or unexported fields
}

Aes Aes加密

func NewAes added in v1.0.3

func NewAes(key, iv string) (a *Aes, err error)

NewAes 实例化Aes

func NewAesWithBytes added in v1.1.4

func NewAesWithBytes(key, iv []byte) (a *Aes, err error)

NewAesWithBytes 实例化Aes

func (*Aes) CbcDecrypt added in v1.0.3

func (a *Aes) CbcDecrypt(secretData []byte) (data []byte, err error)

CbcDecrypt cbc解密

func (*Aes) CbcEncrypt added in v1.0.3

func (a *Aes) CbcEncrypt(plain []byte) (secretData []byte)

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数据结构

func NewBitmap

func NewBitmap(data []byte) 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"`
}

func (*Config) IsEnv added in v1.2.5

func (c *Config) IsEnv(env string) bool

type Container added in v1.2.5

type Container struct {
	// contains filtered or unexported fields
}

func (*Container) Config added in v1.2.5

func (c *Container) Config() *Config

Config 获取配置文件

func (*Container) Get added in v1.2.5

func (c *Container) Get(key string) (value interface{}, exists bool)

Get 从容器中获取值

func (*Container) Set added in v1.2.5

func (c *Container) Set(key string, value interface{})

Set 向容器中写入值

func (*Container) SetConfig added in v1.2.5

func (c *Container) SetConfig(value *Config)

SetConfig 修改配置

type Context added in v1.1.3

type Context struct {
	// contains filtered or unexported fields
}

Context 上下文

func AcquireCtx added in v1.1.3

func AcquireCtx(handlers []func(ctx *Context)) *Context

AcquireCtx 申请Context

func (*Context) Abort added in v1.1.3

func (c *Context) Abort()

func (*Context) Close added in v1.1.3

func (c *Context) Close()

Close 释放Context

func (*Context) Deadline added in v1.1.3

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done added in v1.1.3

func (c *Context) Done() <-chan struct{}

func (*Context) Err added in v1.1.3

func (c *Context) Err() error

func (*Context) Get added in v1.1.3

func (c *Context) Get(key string) (value interface{}, exists bool)

Get 获取数据

func (*Context) GetBool added in v1.1.3

func (c *Context) GetBool(key string) (value bool, exists bool)

GetBool 获取bool值

func (*Context) GetInt added in v1.1.3

func (c *Context) GetInt(key string) (value int, exists bool)

GetInt 获取int值

func (*Context) GetInt64 added in v1.1.3

func (c *Context) GetInt64(key string) (value int64, exists bool)

GetInt64 获取int64值

func (*Context) GetInt8 added in v1.1.3

func (c *Context) GetInt8(key string) (value int8, exists bool)

GetInt8 获取bool值

func (*Context) GetString added in v1.1.3

func (c *Context) GetString(key string) (value string, exists bool)

GetString 获取string值

func (*Context) IsAborted added in v1.1.3

func (c *Context) IsAborted() bool

func (*Context) Next added in v1.1.3

func (c *Context) Next()

func (*Context) Set added in v1.1.3

func (c *Context) Set(key string, value interface{})

Set 存储数据

func (*Context) Value added in v1.1.3

func (c *Context) Value(key interface{}) interface{}

type GetMachineId added in v1.0.8

type GetMachineId func() (id int64, err error)

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

func NewHashRing(servers ...CanHash) HashRing

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 接口

func NewHashSet

func NewHashSet(size int) HashSet

NewHashSet 实例化HashSet

type I18n added in v1.0.3

type I18n interface {
	// T 翻译
	T(key, language string) (msg string)
}

I18n 多语言接口

func NewI18n added in v1.0.3

func NewI18n(defaultLanguage string, msgMap map[string]map[string]string) (i I18n, err error)

NewI18n 实例化多语言

func NewI18nFromJson added in v1.0.3

func NewI18nFromJson(defaultLanguage string, dir string) (i I18n, err error)

NewI18nFromJson 从Json文件配置实例化多语言

func NewI18nFromYaml added in v1.0.3

func NewI18nFromYaml(defaultLanguage string, dir string) (i I18n, err error)

NewI18nFromYaml 从Yaml文件配置实例化多语言

type JsonParam added in v1.2.1

type JsonParam map[string]interface{}

func UnmarshalJsonParam added in v1.2.1

func UnmarshalJsonParam(data []byte) (JsonParam, error)

UnmarshalJsonParam _

func (JsonParam) Exists added in v1.2.1

func (jp JsonParam) Exists(key string) bool

Exists key是否存在,返回bool值

func (JsonParam) Float64 added in v1.2.1

func (jp JsonParam) Float64(key string) float64

Float64 获取float64,如果不是float64,返回0

func (JsonParam) Int added in v1.2.1

func (jp JsonParam) Int(key string) int

Int 获取Int,如果不是int,返回0

func (JsonParam) Int64 added in v1.2.1

func (jp JsonParam) Int64(key string) int64

Int64 获取Int64,如果不是float64,返回0

func (JsonParam) Int64Slice added in v1.2.1

func (jp JsonParam) Int64Slice(key string) []int64

Int64Slice 获取[]int64,获取失败返回nil

func (JsonParam) IntSlice added in v1.2.1

func (jp JsonParam) IntSlice(key string) []int

IntSlice 获取[]int,获取失败,返回nil

func (JsonParam) JsonMarshal added in v1.2.1

func (jp JsonParam) JsonMarshal() []byte

JsonMarshal _

func (JsonParam) String added in v1.2.1

func (jp JsonParam) String(key string) string

String 获取string值,如果不是string类型,返回""

func (JsonParam) StringSlice added in v1.2.1

func (jp JsonParam) StringSlice(key string) []string

StringSlice 获取[]string,如果不是[]string返回nil

func (JsonParam) Uint32Slice added in v1.2.1

func (jp JsonParam) Uint32Slice(key string) []uint32

Uint32Slice 获取[]uint32,获取失败返回nil

type Node added in v1.0.9

type Node struct {
	// contains filtered or unexported fields
}

type NodeList added in v1.0.9

type NodeList []Node

func (NodeList) Len added in v1.0.9

func (n NodeList) Len() int

func (NodeList) Less added in v1.0.9

func (n NodeList) Less(i, j int) bool

func (NodeList) Swap added in v1.0.9

func (n NodeList) Swap(i, j int)

type Package added in v1.2.6

type Package struct {
	Id    uint16    `json:"id"`
	Name  string    `json:"name"`
	Param JsonParam `json:"param"`
}

func (*Package) Pack added in v1.2.6

func (p *Package) Pack() []byte

func (*Package) Unpack added in v1.2.6

func (p *Package) Unpack(data []byte) error

type Protocol added in v1.2.7

type Protocol interface {
	Pack(pkg *Package) []byte
	ResponseKey() []byte
	Unpack(data []byte) (pkg *Package, err error)
}

func NewV0 added in v1.2.7

func NewV0() (protocol Protocol, err error)

func NewV1 added in v1.2.6

func NewV1(aes *Aes, secretData []byte) (protocol Protocol, err error)

func NewV2 added in v1.2.7

func NewV2(aes *Aes, secretData []byte) (protocol Protocol, err error)

func NewV2ForClient added in v1.2.9

func NewV2ForClient(aes *Aes, key, secretData []byte) (protocol Protocol, err error)

type Rsa added in v1.0.3

type Rsa struct {
	// contains filtered or unexported fields
}

Rsa Rsa

func NewRsa added in v1.0.3

func NewRsa(publicKey, privateKey string) (r *Rsa, err error)

NewRsa 实例化Rsa

func NewRsaWithPkcs1 added in v1.0.6

func NewRsaWithPkcs1(publicKey, privateKey string) (r *Rsa, err error)

NewRsaWithPkcs1 pkcs1实例化Rsa

func NewRsaWithPkcs8 added in v1.0.6

func NewRsaWithPkcs8(publicKey, privateKey string) (r *Rsa, err error)

NewRsaWithPkcs8 pkcs8实例化Rsa

func (*Rsa) Decrypt added in v1.0.3

func (r *Rsa) Decrypt(secretData []byte) ([]byte, error)

Decrypt 解密

func (*Rsa) Encrypt added in v1.0.3

func (r *Rsa) Encrypt(data []byte) ([]byte, error)

Encrypt 加密

func (*Rsa) Sign added in v1.0.3

func (r *Rsa) Sign(data []byte, algorithmSign crypto.Hash) ([]byte, error)

Sign 数据签名

func (*Rsa) Verify added in v1.0.3

func (r *Rsa) Verify(data []byte, sign []byte, algorithmSign crypto.Hash) bool

Verify 数据验签

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

func NewShardMap

func NewShardMap() ShardMap

NewShardMap 实例化ShardMap

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 NewSF added in v1.0.8

func NewSF(mode uint8, id uint8, timeStampBegin int64) (sfl SnowFlake, err error)

NewSF 实例化雪花算法

func NewSFByIp added in v1.0.8

func NewSFByIp(mode uint8, timeStampBegin int64) (sfl SnowFlake, err error)

NewSFByIp ip方式实例化雪花算法

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

func StatusWithCode(code codes.Code) *Status

StatusWithCode 指定Code获取一个Status

func StatusWithJsonUnmarshal added in v1.2.3

func StatusWithJsonUnmarshal(data []byte) (*Status, error)

StatusWithJsonUnmarshal 指定json []byte获取一个Status

func (*Status) Close added in v1.2.3

func (s *Status) Close()

Close 释放Status到sync.Pool

func (*Status) ConvertGrpcStatus added in v1.2.3

func (s *Status) ConvertGrpcStatus(details ...proto.Message) (*status.Status, error)

ConvertGrpcStatus 转换为grpc状态码

func (*Status) Error added in v1.2.3

func (s *Status) Error() error

Error 转换为error

func (*Status) Is added in v1.2.3

func (s *Status) Is(code codes.Code) bool

Is 判断是否是指定Code

func (*Status) IsOK added in v1.2.3

func (s *Status) IsOK() bool

IsOK 操作是否OK

func (*Status) JsonMarshal added in v1.2.3

func (s *Status) JsonMarshal() []byte

JsonMarshal _

func (*Status) WithData added in v1.2.3

func (s *Status) WithData(data interface{}) *Status

WithData 附加自定义Data

func (*Status) WithMsg added in v1.2.3

func (s *Status) WithMsg(msg string) *Status

WithMsg 附加自定义message

Directories

Path Synopsis
core
examples
gopool command
i18n command
shardmap command

Jump to

Keyboard shortcuts

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