utils

package module
v0.0.0-...-a26ca6a Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 43 Imported by: 80

README

utils

介绍

工具

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Overview

指数退避算法

动态扩展的channl

Package lru implements an LRU cache.

Package multihash is the Go implementation of https://github.com/multiformats/multihash, or self-describing hashes.

投票系统

Index

Constants

View Source
const (
	ERROR_CODE_success             = 60000 //成功
	ERROR_CODE_system_error_remote = 60001 //系统错误--远程节点
	ERROR_CODE_system_error_self   = 60002 //系统错误--自己节点
)
View Source
const (
	// DBKeySize              = 8                  //dbkey为uint64大端序列化的[]byte,避免查询时与短前缀混合,规定固定长度为8
	MaxKeySize           = 65535              //max key size
	MaxValueSize     int = 1024 * 1024 * 1024 //max value size
	DBRemoveNum          = 100                //分批次删除map集合中的数据,每批次默认数量
	DBRemoveInterval     = time.Second        //分批次删除map集合中的数据,每批次默认间隔时间

)
View Source
const (
	ID         = 0x00
	SHA1       = 0x11
	SHA2_256   = 0x12
	SHA2_512   = 0x13
	SHA3_224   = 0x17
	SHA3_256   = 0x16
	SHA3_384   = 0x15
	SHA3_512   = 0x14
	SHA3       = SHA3_512
	KECCAK_224 = 0x1A
	KECCAK_256 = 0x1B
	KECCAK_384 = 0x1C
	KECCAK_512 = 0x1D

	SHAKE_128 = 0x18
	SHAKE_256 = 0x19

	BLAKE2B_MIN = 0xb201
	BLAKE2B_MAX = 0xb240
	BLAKE2S_MIN = 0xb241
	BLAKE2S_MAX = 0xb260

	DBL_SHA2_256 = 0x56

	MURMUR3 = 0x22
)

constants

View Source
const AES_CTR_DEFAULT_KEY = "AES_CTR_DEFAULT_KEY" //默认密码

Variables

View Source
var (
	DataType_Index      = []byte{1} //保存自增长ID
	DataType_Data_Map   = []byte{2} //Map结构数据保存
	DataType_Data_List  = []byte{3} //List结构数据保存
	DataType_Map_In_Map = []byte{4} //map in the map结构
)
View Source
var (
	ErrUnknownCode      = errors.New("unknown multihash code")
	ErrTooShort         = errors.New("multihash too short. must be > 3 bytes")
	ErrTooLong          = errors.New("multihash too long. must be < 129 bytes")
	ErrLenNotSupported  = errors.New("multihash does not yet support digests longer than 127 bytes")
	ErrInvalidMultihash = errors.New("input isn't valid multihash")

	ErrVarintBufferShort = errors.New("uvarint: buffer too small")
	ErrVarintTooLong     = errors.New("uvarint: varint too big (max 64bit)")
)

errors

View Source
var Codes = map[uint64]string{
	ID:           "id",
	SHA1:         "sha1",
	SHA2_256:     "sha2-256",
	SHA2_512:     "sha2-512",
	SHA3_224:     "sha3-224",
	SHA3_256:     "sha3-256",
	SHA3_384:     "sha3-384",
	SHA3_512:     "sha3-512",
	DBL_SHA2_256: "dbl-sha2-256",
	MURMUR3:      "murmur3",
	KECCAK_224:   "keccak-224",
	KECCAK_256:   "keccak-256",
	KECCAK_384:   "keccak-384",
	KECCAK_512:   "keccak-512",
	SHAKE_128:    "shake-128",
	SHAKE_256:    "shake-256",
}

Codes maps a hash code to it's name

View Source
var DefaultLengths = map[uint64]int{
	ID:           -1,
	SHA1:         20,
	SHA2_256:     32,
	SHA2_512:     64,
	SHA3_224:     28,
	SHA3_256:     32,
	SHA3_384:     48,
	SHA3_512:     64,
	DBL_SHA2_256: 32,
	KECCAK_224:   28,
	KECCAK_256:   32,
	MURMUR3:      4,
	KECCAK_384:   48,
	KECCAK_512:   64,
	SHAKE_128:    32,
	SHAKE_256:    64,
}

DefaultLengths maps a hash code to it's default length

View Source
var Name_pro []string //名称前缀 rune
View Source
var Name_suffix_long []string //名称后缀(长)
View Source
var Name_suffix_short []string //名称后缀(短)
View Source
var Names = map[string]uint64{
	"id":           ID,
	"sha1":         SHA1,
	"sha2-256":     SHA2_256,
	"sha2-512":     SHA2_512,
	"sha3":         SHA3_512,
	"sha3-224":     SHA3_224,
	"sha3-256":     SHA3_256,
	"sha3-384":     SHA3_384,
	"sha3-512":     SHA3_512,
	"dbl-sha2-256": DBL_SHA2_256,
	"murmur3":      MURMUR3,
	"keccak-224":   KECCAK_224,
	"keccak-256":   KECCAK_256,
	"keccak-384":   KECCAK_384,
	"keccak-512":   KECCAK_512,
	"shake-128":    SHAKE_128,
	"shake-256":    SHAKE_256,
}

Names maps the name of a hash to the code

View Source
var Quant *ledis.DB

Functions

func AddTimetask

func AddTimetask(tick int64, fn f, class string, params []byte)

添加一个定时任务 @tick int64 未来的某个时刻,例如(未来10秒钟后执行):time.Now().Unix()+int64(10)

func AesCTR_Decrypt

func AesCTR_Decrypt(key, iv, cipherText []byte) ([]byte, error)

解密 @key []byte 加密密码 @iv []byte 加密向量 @cipherText []byte 待解密字节

func AesCTR_Decrypt_File

func AesCTR_Decrypt_File(key, iv []byte, cipherFilePath, plainFilePath string) error

解密文件

func AesCTR_Encrypt

func AesCTR_Encrypt(key, iv, plainText []byte) ([]byte, error)

加密 @key []byte 加密密码 @iv []byte 加密向量 @plainText []byte 待加密字节

func AesCTR_Encrypt_File

func AesCTR_Encrypt_File(key, iv []byte, plainFilePath, cipherFilePath string) error

加密文件 @key []byte 加密密码 @iv []byte 加密向量 @plainFilePath string 待加密的文件路径 @cipherFilePath string 加密后的文件保存路径

func AppCode

func AppCode(code uint64) bool

AppCode checks whether a multihash code is part of the App range.

func BuildGender

func BuildGender() int

随机构建一个性别

func BuildKeyToByte

func BuildKeyToByte(t, key string) (prkbs string)

func BuildMerkleRoot

func BuildMerkleRoot(tx [][]byte) []byte

构建默克尔树根

func BuildName

func BuildName() string

随机构建一个名称

func Bytes2string

func Bytes2string(b []byte) string

把[]byte转换为string,只要性能,不在乎可读性

func BytesToInt64

func BytesToInt64(b []byte) int64

byte转int64

func BytesToUint16

func BytesToUint16(b []byte) uint16

byte转uint16

func BytesToUint16ByBigEndian

func BytesToUint16ByBigEndian(b []byte) uint16

byte转uint16,大端字节序

func BytesToUint32

func BytesToUint32(b []byte) uint32

byte转uint64

func BytesToUint64

func BytesToUint64(b []byte) uint64

byte转uint64,小端字节序

func BytesToUint64ByBigEndian

func BytesToUint64ByBigEndian(b []byte) uint64

byte转uint64,大端字节序

func ChangeMap

func ChangeMap(v interface{}) (map[string]interface{}, error)

把一个对象转换成map

func Check

func Check(message string, zeroes int, nonce int) bool

检查是否完成工作

func CheckCreateDir

func CheckCreateDir(dir_path string) error

检查目录是否存在,不存在则创建

func CheckNonce

func CheckNonce(code []byte, zeroes uint64) bool

检查hash值是否有足够多的前导零 @code string Hash值 @zeroes uint64 前导零个数

func DenBase64

func DenBase64(str string) (bs []byte, err error)

func DistinctString

func DistinctString(list []string) []string

去除重复,不保证顺序

func EnBase64

func EnBase64(bs []byte) string

func Encode

func Encode(buf []byte, code uint64) ([]byte, error)

Encode a hash digest along with the specified function code. Note: the length is derived from the length of the digest itself.

func EncodeName

func EncodeName(buf []byte, name string) ([]byte, error)

EncodeName is like Encode() but providing a string name instead of a numeric code. See Names for allowed values.

func Encrypt

func Encrypt(plantText, key []byte) ([]byte, error)

func EncryptPrk

func EncryptPrk(prkbs, key []byte) []byte

对私钥加密

func FilePathSplit

func FilePathSplit(path string) []string

把文件全路径切分成子路径

func FileSHA3_256

func FileSHA3_256(path string) ([]byte, error)

计算文件的hash值

func FormatIdUtil

func FormatIdUtil(idInt *big.Int) string

格式化id为十进制或十六进制字符串

func FormatTimeToSecond

func FormatTimeToSecond(now time.Time) string

func FullHighPositionZero

func FullHighPositionZero(bs *[]byte, n int) *[]byte

高位补零

func GetAccNumber

func GetAccNumber() uint64

获得累加器的值

func GetAvailablePortForTCP

func GetAvailablePortForTCP(addr string) net.Listener

获得一个可用的TCP端口

func GetAvailablePortForUDP

func GetAvailablePortForUDP() int

获得一个可用的UDP端口

func GetDiskFreeSpace

func GetDiskFreeSpace(dirPath string) (uint64, uint64, uint64, error)

获取磁盘空间大小以及可用空间大小 @return uint64 磁盘总大小 @return uint64 磁盘可用空间大小 @return uint64 磁盘可用空间大小

func GetHashByByte

func GetHashByByte(bs []byte) string

func GetHashForDomain

func GetHashForDomain(domain string) []byte

获得域名的hash值

func GetHashKey

func GetHashKey(account string) *big.Int

通过一个域名和用户名得到节点的id @return 10进制字符串

func GetLocalHost

func GetLocalHost() string

不联网的情况下,得到本机ip地址

func GetLocalIntenetIp

func GetLocalIntenetIp() (string, bool)

获取本机能联网的ip地址 @return string 获得的ip地址 @return bool 是否能联网

func GetNow

func GetNow() int64

获取时间

func GetRandNum

func GetRandNum(n int64) int64

获得一个随机数(0 - n],包含0,不包含n

func GetRandomDomain

func GetRandomDomain() string

随机获取一个域名

func GetRandomOneInt64

func GetRandomOneInt64() int64

随机获取一个int64类型的随机数

func GetStopService

func GetStopService() chan bool

创建一个等待关机命令服务

func GetTCPListener

func GetTCPListener(ip string, port int) (*net.TCPListener, error)

获得一个TCP监听

func GetTimeToken

func GetTimeToken(class string, wait bool) (allow bool)

func GlobalInit

func GlobalInit(kind, path, level string, length int) error

func Go

func Go(f func())

func Hash_SHA3_256

func Hash_SHA3_256(bs []byte) []byte

func Hash_SHA3_512

func Hash_SHA3_512(bs []byte) []byte

func IPV4Long2String

func IPV4Long2String(i uint32) (string, error)

Long2IPString 把数值转为ip字符串

func IPV4String2Long

func IPV4String2Long(ip string) (uint32, error)

IPString2Long 把ip字符串转为数值

func InitBuildRandomName

func InitBuildRandomName()

加载名称前缀和后缀

func InitLedis

func InitLedis(dbpath string)

初始化ledis数据库

func Int64ToBytes

func Int64ToBytes(n int64) []byte

int64转byte

func IsOnlyIp

func IsOnlyIp(ip string) bool

是全球唯一ip

func Key16Padding

func Key16Padding(key []byte) []byte

将加密秘钥填补成16字节长度

func LeveldbBuildKey

func LeveldbBuildKey(key []byte) ([]byte, error)

leveldb中,所有的key都带一个key长度前缀,用2字节保存。 2字节容量是65535,因此key长度不能大于65535。 避免不同长度的key前缀查询的时候混合。

func LeveldbParseKey

func LeveldbParseKey(key []byte) (uint16, []byte, error)

leveldb中,所有的key都带一个key长度前缀,用2字节保存。 2字节容量是65535,因此key长度不能大于65535。 避免不同长度的key前缀查询的时候混合。 @return uint16 长度 @return []byte 解析出来的key

func LeveldbParseKeyMore

func LeveldbParseKeyMore(key []byte) ([][]byte, error)

多个长度+[]byte拼接,通过长度解析出来多个数据。不能有不符合规范的数据,有则报错

func Mkdir

func Mkdir(path string) error

递归创建目录

func NewLeveldbKey

func NewLeveldbKey(key []byte) (leveldbKey, error)

func NewPollManager

func NewPollManager() *pollManager

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func ParseKeyToByte

func ParseKeyToByte(prkbs []byte) []byte

-----BEGIN EC PRIVATE KEY----- MIHcAgEBBEIAJuVZ2ujd64R6iA3mJ2Iuaorwc3kUXihcLvF51nuF8MHE82ZobU4k JBwOjjFX1jjZGDAyiIgXpD9HXtfIWCpIksigBwYFK4EEACOhgYkDgYYABAB7ZnsN kzgg7JrVxohq2FOxRpA+bUsVsxHKHRur0ezttNRu7ldR36fGgyztoplyUltUndID 7EEi2o9z2E4q99ozOgHwbHnx5WROGYtwvdwDQtvHnCynzO7eixMFZ8pKLddz7YLs hm8sApO1ZneSDMMBoKhtlX4+pywXZ91WxEfOY/GXlA== -----END EC PRIVATE KEY-----

将这种格式的[]byte,去掉头和尾后拼接中间的字符

func PathExists

func PathExists(path string) (bool, error)

判断一个路径的文件是否存在

func PprofMem

func PprofMem(timeout time.Duration)

go tool pprof -http 127.0.0.1:8081 .\mem.prof

func Print

func Print(findInt *big.Int)

func PrintPanicStack

func PrintPanicStack()

错误处理

func RandString

func RandString(strs ...string) string

字符串中随机选择一个

func SaveFile

func SaveFile(name string, bs *[]byte) error

保存文件 保存文件步骤: 1.创建临时文件 2.删除原文件 3.修改临时文件名称为原文件名称

func SaveJsonFile

func SaveJsonFile(name string, o interface{}) error

保存对象为json格式

func SetTimeToken

func SetTimeToken(class string, t time.Duration)

func StartOtherTime

func StartOtherTime() error

func StartSystemTime

func StartSystemTime() error

func StopMemProfile

func StopMemProfile(memProfile, cpuProfile *os.File)

func StopService

func StopService()

发送停止命令

func TimeFormatToNanosecond

func TimeFormatToNanosecond() string

func TimeFormatToNanosecondStr

func TimeFormatToNanosecondStr() string

func Uint16ToBytes

func Uint16ToBytes(n uint16) []byte

uint16转byte

func Uint16ToBytesByBigEndian

func Uint16ToBytesByBigEndian(n uint16) []byte

uint16转byte,大端字节序

func Uint32ToBytes

func Uint32ToBytes(n uint32) []byte

uint64转byte

func Uint64ToBytes

func Uint64ToBytes(n uint64) []byte

uint64转byte,小端字节序

func Uint64ToBytesByBigEndian

func Uint64ToBytesByBigEndian(n uint64) []byte

uint64转byte,大端字节序

func ValidCode

func ValidCode(code uint64) bool

ValidCode checks whether a multihash code is valid.

func Work

func Work(message string, zeroes int) int

开始工作,猜解一段字符串hash后有足够个0 目前(2014年)一般计算机计算出20个0大约一百万次,用时3.0121722秒

Types

type BackoffTimer

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

func NewBackoffTimer

func NewBackoffTimer(n ...int64) *BackoffTimer

间隔n秒后发送一个信号

func (*BackoffTimer) Release

func (this *BackoffTimer) Release()

立即释放暂停的程序

func (*BackoffTimer) Reset

func (this *BackoffTimer) Reset()

重置 间隔时间从头开始

func (*BackoffTimer) Wait

func (this *BackoffTimer) Wait() int64

等待时间 @return int64 等待的时间

type BackoffTimerChan

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

func NewBackoffTimerChan

func NewBackoffTimerChan(n ...time.Duration) *BackoffTimerChan

间隔n秒后发送一个信号

func (*BackoffTimerChan) Release

func (this *BackoffTimerChan) Release()

立即释放暂停的程序

func (*BackoffTimerChan) Reset

func (this *BackoffTimerChan) Reset()

重置 间隔时间从头开始

func (*BackoffTimerChan) Wait

等待时间 @return time.Duration 等待的时间

type BeegoLog

type BeegoLog struct {
	// contains filtered or unexported fields
}
var (
	Log *BeegoLog
)

func (*BeegoLog) Debug

func (this *BeegoLog) Debug(format string, v ...interface{})

func (*BeegoLog) Error

func (this *BeegoLog) Error(format string, v ...interface{})

func (*BeegoLog) Info

func (this *BeegoLog) Info(format string, v ...interface{})

func (*BeegoLog) Warn

func (this *BeegoLog) Warn(format string, v ...interface{})

type BufferByte

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

func NewBufferByte

func NewBufferByte(length int) *BufferByte

func (*BufferByte) Bytes

func (this *BufferByte) Bytes() (bs *[]byte)

func (*BufferByte) Clean

func (this *BufferByte) Clean()

清空缓冲区

func (*BufferByte) Length

func (this *BufferByte) Length() (n int)

func (*BufferByte) SetLength

func (this *BufferByte) SetLength(maxLength int)

设置缓冲大小,只能往大了设置,不能缩小

func (*BufferByte) Write

func (this *BufferByte) Write(bs *[]byte)

type Cache

type Cache struct {
	// MaxEntries is the maximum number of cache entries before
	// an item is evicted. Zero means no limit.
	MaxEntries int

	// OnEvicted optionally specificies a callback function to be
	// executed when an entry is purged from the cache.
	OnEvicted func(key Key, value interface{})
	// contains filtered or unexported fields
}

Cache is an LRU cache. It is not safe for concurrent access.

func NewCache

func NewCache(maxEntries int) *Cache

New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add

func (c *Cache) Add(key Key, value interface{})

Add adds a value to the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all stored items from the cache.

func (*Cache) Get

func (c *Cache) Get(key Key) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key Key)

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type ChanDynamic

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

动态大小的管道

func NewChanDynamic

func NewChanDynamic(chanLen uint64) *ChanDynamic

创建一个动态管道

func (*ChanDynamic) Add

func (this *ChanDynamic) Add(one interface{})

func (*ChanDynamic) Get

func (this *ChanDynamic) Get(contextRoot context.Context) interface{}

type DBItem

type DBItem struct {
	Index []byte
	Key   []byte
	Value []byte
}

集合中的项目

type DBLedis

type DBLedis struct {
	DB *ledis.DB
	// contains filtered or unexported fields
}

DBConn leveldb 连接

func (*DBLedis) InitDB

func (db *DBLedis) InitDB(name string) (curDB *ledis.DB, err error)

InitDB 初始化数据库

type DecodedMultihash

type DecodedMultihash struct {
	Code   uint64
	Name   string
	Length int    // Length is just int as it is type of len() opearator
	Digest []byte // Digest holds the raw multihash bytes
}

DecodedMultihash represents a parsed multihash and allows easy access to the different parts of a multihash.

func Decode

func Decode(buf []byte) (*DecodedMultihash, error)

Decode parses multihash bytes into a DecodedMultihash.

type ERROR

type ERROR struct {
	Code uint64 `json:"c"` //业务错误编号
	Msg  string `json:"m"` //错误信息
}

func NewErrorBus

func NewErrorBus(code uint64, msg string) ERROR

创建一个业务错误

func NewErrorSuccess

func NewErrorSuccess() ERROR

创建一个返回成功

func NewErrorSysRemote

func NewErrorSysRemote(msg string) ERROR

创建一个远端节点的系统错误

func NewErrorSysSelf

func NewErrorSysSelf(err error) ERROR

创建一个系统错误

func ParseERROR

func ParseERROR(bs []byte) (*ERROR, error)

func (*ERROR) CheckSuccess

func (this *ERROR) CheckSuccess() bool

检查这个错误类型是否是成功

func (*ERROR) Proto

func (this *ERROR) Proto() (*[]byte, error)

func (*ERROR) String

func (this *ERROR) String() string

检查这个错误类型是否是成功

type ErrInconsistentLen

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

ErrInconsistentLen is returned when a decoded multihash has an inconsistent length

func (ErrInconsistentLen) Error

func (e ErrInconsistentLen) Error() string

type KVPair

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

func NewKVPair

func NewKVPair(isAddOrDel bool, key, value []byte) (*KVPair, error)

type Key

type Key interface{}

A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators

type LedisDB

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

func CreateLedisDB

func CreateLedisDB(path string) (*LedisDB, error)

func (*LedisDB) AddZSet

func (this *LedisDB) AddZSet(name, member *[]byte, orderId int64) error

添加一个数据到zset

func (*LedisDB) AddZSetAutoincrId

func (this *LedisDB) AddZSetAutoincrId(name *[]byte, member []byte, duration int64) error

添加一个数据到zset,id为自增长

func (*LedisDB) CheckHashExist

func (this *LedisDB) CheckHashExist(hash []byte) (bool, error)

检查key是否存在 @return bool true:存在;false:不存在;

func (*LedisDB) CheckNullDB

func (this *LedisDB) CheckNullDB(key []byte) (bool, error)

检查是否是空数据库

func (*LedisDB) DelZSet

func (this *LedisDB) DelZSet(name *[]byte, min, max int64) error

删除zset中一定范围score的数据

func (*LedisDB) DelZSetAll

func (this *LedisDB) DelZSetAll(name *[]byte) error

添加一个数据到zset

func (*LedisDB) DelZSetByMembers

func (this *LedisDB) DelZSetByMembers(name *[]byte, members ...[]byte) error

删除zset中多个members

func (*LedisDB) Find

func (this *LedisDB) Find(txId []byte) (*[]byte, error)

查找

func (*LedisDB) GetDB

func (this *LedisDB) GetDB() *ledis.DB

获取数据库连接

func (*LedisDB) GetRangeZSet

func (ldb *LedisDB) GetRangeZSet(name *[]byte, start, stop int) (*[]ledis.ScorePair, error)

* 查询根据 start stop 查询返回zset

func (*LedisDB) GetZSetAll

func (this *LedisDB) GetZSetAll(name *[]byte) (*[]ledis.ScorePair, error)

添加一个数据到zset

func (*LedisDB) GetZSetByMember

func (this *LedisDB) GetZSetByMember(name *[]byte, member []byte) (int64, error)

获取一个member的下标,如果不存在,则返回-1

func (*LedisDB) GetZSetPage

func (this *LedisDB) GetZSetPage(name *[]byte, min, max int64, count int) (*[]ledis.ScorePair, error)

添加一个数据到zset

func (*LedisDB) InitDB

func (this *LedisDB) InitDB() (err error)

链接leveldb

func (*LedisDB) LRange

func (ldb *LedisDB) LRange(key []byte, start, end int32) ([][]byte, error)

*

  • 获取List

func (*LedisDB) Remove

func (this *LedisDB) Remove(id []byte) error

删除

func (*LedisDB) Rpush

func (ldb *LedisDB) Rpush(key, val []byte) (int64, error)

*

  • 添加一个List

func (*LedisDB) Save

func (this *LedisDB) Save(id []byte, bs *[]byte) error

保存

func (*LedisDB) SetExpire

func (ldb *LedisDB) SetExpire(key *[]byte, duration int64) (int64, error)

* 设置key 过期时间 单位秒

func (*LedisDB) ZSetCard

func (this *LedisDB) ZSetCard(name *[]byte) (n int64, err error)

得到一个数据到zset,数量

type LevelDB

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

func CreateLevelDB

func CreateLevelDB(path string) (*LevelDB, error)

func (*LevelDB) CheckHashExist

func (this *LevelDB) CheckHashExist(hash []byte) bool

检查key是否存在 @return bool true:存在;false:不存在;

func (*LevelDB) CheckNullDB

func (this *LevelDB) CheckNullDB(key []byte) (bool, error)

检查是否是空数据库

func (*LevelDB) Close

func (this *LevelDB) Close()

关闭leveldb连接

func (*LevelDB) Find

func (this *LevelDB) Find(txId []byte) (*[]byte, error)

查找

func (*LevelDB) FindList

func (this *LevelDB) FindList(dbkey []byte) ([]DBItem, error)

查询List集合中的所有项目

func (*LevelDB) FindMap

func (this *LevelDB) FindMap(dbkey, key []byte) ([]byte, error)

查询Map

func (*LevelDB) FindMapAllToList

func (this *LevelDB) FindMapAllToList(dbkey []byte) ([]DBItem, error)

查询Map中所有的key和value值

func (*LevelDB) FindMapInListAllKeyToList

func (this *LevelDB) FindMapInListAllKeyToList(dbkey []byte) ([]DBItem, error)

查询MapInList集合中所有key

func (*LevelDB) FindMapInListByIndex

func (this *LevelDB) FindMapInListByIndex(dbkey, key []byte, index uint64) ([]byte, error)

查找MapInList集合中的一个key的value值

func (*LevelDB) FindMapInListCount

func (this *LevelDB) FindMapInListCount(dbkey, key []byte) (uint64, error)

查询MapInList集合中一个key下的列表记录总数

func (*LevelDB) FindMapInListKeyList

func (this *LevelDB) FindMapInListKeyList(dbkey, key []byte) ([]DBItem, error)

查询MapInList集合中一个key下的列表

func (*LevelDB) FindMapInMapByKeyIn

func (this *LevelDB) FindMapInMapByKeyIn(dbkey, keyOut, keyIn []byte) ([]byte, error)

查询 Map中有Map 集合中内层key对应的值 @dbkey []byte 数据库ID @keyOut []byte 外层map索引 @keyIn []byte 内层map索引 @return []byte 内层map索引对应的值

func (*LevelDB) FindPrefixKeyAll

func (this *LevelDB) FindPrefixKeyAll(tag []byte) ([][]byte, [][]byte, error)

查询指定前缀的key

func (*LevelDB) GetDB

func (this *LevelDB) GetDB() *leveldb.DB

获取数据库连接

func (*LevelDB) InitDB

func (this *LevelDB) InitDB() (err error)

链接leveldb

func (*LevelDB) PrintAll

func (this *LevelDB) PrintAll() ([][]byte, error)

打印所有key

func (*LevelDB) Remove

func (this *LevelDB) Remove(id []byte) error

删除

func (*LevelDB) RemoveMapByDbKey

func (this *LevelDB) RemoveMapByDbKey(dbkey []byte, num uint64, interval time.Duration) error

删除Map 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间

func (*LevelDB) RemoveMapByKey

func (this *LevelDB) RemoveMapByKey(dbkey, key []byte) error

删除Map中的一个key

func (*LevelDB) RemoveMapInListByIndex

func (this *LevelDB) RemoveMapInListByIndex(dbkey, key []byte, index uint64) error

删除MapInList集合中的一个item

func (*LevelDB) RemoveMapInListByKey

func (this *LevelDB) RemoveMapInListByKey(dbkey, key []byte) error

删除MapInList集合中的一个key

func (*LevelDB) RemoveMapInListByKeyInterval

func (this *LevelDB) RemoveMapInListByKeyInterval(dbkey, key []byte, num uint64, interval time.Duration) error

间隔删除MapInList集合中的一个key 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间

func (*LevelDB) RemoveMapInMapByKeyIn

func (this *LevelDB) RemoveMapInMapByKeyIn(dbkey, keyOut, keyIn []byte) error

查询 Map中有Map 集合中内层key对应的值 @dbkey []byte 数据库ID @keyOut []byte 外层map索引 @keyIn []byte 内层map索引 @return []byte 内层map索引对应的值

func (*LevelDB) RemoveMapInMapByKeyOutInterval

func (this *LevelDB) RemoveMapInMapByKeyOutInterval(dbkey, keyOut []byte, num uint64, interval time.Duration) error

间隔删除 Map中有Map 集合中外层key对应的值 当删除大量数据时,会花很长时间,长期占用数据库,让其他业务无法使用数据库。 可以分批次删除,并且设置每批次间隔时间 @dbkey []byte 数据库ID @keyOut []byte 外层map索引 @num uint64 一次删除条数 @interval time.Duration 删除间隔时间

func (*LevelDB) Save

func (this *LevelDB) Save(id []byte, bs *[]byte) error

保存

func (*LevelDB) SaveList

func (this *LevelDB) SaveList(dbkey, value []byte) (uint64, error)

保存到List集合中

func (*LevelDB) SaveMap

func (this *LevelDB) SaveMap(dbkey, key, value []byte) error

保存到Map

func (*LevelDB) SaveMapInList

func (this *LevelDB) SaveMapInList(dbkey, key, value []byte) (uint64, error)

保存到MapInList集合中

func (*LevelDB) SaveMapInMap

func (this *LevelDB) SaveMapInMap(dbkey, keyOut, keyIn, value []byte) error

保存到 Map中有Map 集合中 @dbkey []byte 数据库ID @keyOut []byte 外层map索引 @keyIn []byte 内层map索引 @value []byte 内层map索引对应的值

func (*LevelDB) SaveMapMore

func (this *LevelDB) SaveMapMore(dbkey []byte, kvs ...KVPair) error

保存到Map,可以一次保存多个

func (*LevelDB) Tags

func (this *LevelDB) Tags(tag []byte) ([][]byte, error)

根据Tags遍历

func (*LevelDB) UpdateMapInListByIndex

func (this *LevelDB) UpdateMapInListByIndex(dbkey, key []byte, index uint64, value []byte) error

修改MapInList集合中的一个key的value值

type Multihash

type Multihash []byte

Multihash is byte slice with the following form: <hash function code><digest size><hash function output>. See the spec for more information.

func Cast

func Cast(buf []byte) (Multihash, error)

Cast casts a buffer onto a multihash, and returns an error if it does not work.

func FromB58String

func FromB58String(s string) (m Multihash, err error)

FromB58String parses a B58-encoded multihash.

func FromHexString

func FromHexString(s string) (Multihash, error)

FromHexString parses a hex-encoded multihash.

func (*Multihash) B58String

func (m *Multihash) B58String() string

B58String returns the B58-encoded representation of a multihash.

func (*Multihash) Data

func (m *Multihash) Data() []byte

func (*Multihash) HexString

func (m *Multihash) HexString() string

HexString returns the hex-encoded representation of a multihash.

func (*Multihash) String

func (m *Multihash) String() string

String is an alias to HexString().

type Multihashs

type Multihashs struct {
	Multihash `json:"mutihash"`
	B58string string `json:"b58string"`
}

func Casts

func Casts(buf []byte) (Multihashs, error)

func FromB58Strings

func FromB58Strings(s string) (m Multihashs, err error)

func FromHexStrings

func FromHexStrings(s string) (Multihashs, error)

func NewMultihashs

func NewMultihashs(data []byte) Multihashs

func (*Multihashs) B58String

func (m *Multihashs) B58String() string

func (*Multihashs) Byte

func (m *Multihashs) Byte() []byte

type SyncList

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

func NewSyncList

func NewSyncList() *SyncList

func (*SyncList) Add

func (this *SyncList) Add(obj interface{})

func (*SyncList) Get

func (this *SyncList) Get(index int) (n interface{})

func (*SyncList) GetAll

func (this *SyncList) GetAll() []interface{}

func (*SyncList) Remove

func (this *SyncList) Remove(index int) (ok bool)

type SyncTimeFun

type SyncTimeFun func() (int64, error)

type Task

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

func NewTask

func NewTask(function f) *Task

func (*Task) Add

func (this *Task) Add(tick int64, class string, params []byte)

@tick int64 执行的时间(时间戳) @class string 执行的命令 @params string 字符串参数

func (*Task) Destroy

func (this *Task) Destroy()

销毁,回收协程

func (*Task) Len

func (this *Task) Len() int

func (*Task) Less

func (this *Task) Less(i, j int) bool

func (*Task) Remove

func (this *Task) Remove(tick int64, class string, params []byte)

func (*Task) Swap

func (this *Task) Swap(i, j int)

type Tick

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

func NewTick

func NewTick(tick int64, class string, params []byte) *Tick

type Ticks

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

func NewTicks

func NewTicks(tick Tick) *Ticks

Directories

Path Synopsis
crc
Package crc implements generic CRC calculations up to 64 bits wide.
Package crc implements generic CRC calculations up to 64 bits wide.
dh
protos

Jump to

Keyboard shortcuts

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