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
- Variables
- func AddTimetask(tick int64, fn f, class string, params []byte)
- func AesCTR_Decrypt(key, iv, cipherText []byte) ([]byte, error)
- func AesCTR_Decrypt_File(key, iv []byte, cipherFilePath, plainFilePath string) error
- func AesCTR_Encrypt(key, iv, plainText []byte) ([]byte, error)
- func AesCTR_Encrypt_File(key, iv []byte, plainFilePath, cipherFilePath string) error
- func AppCode(code uint64) bool
- func BuildGender() int
- func BuildKeyToByte(t, key string) (prkbs string)
- func BuildMerkleRoot(tx [][]byte) []byte
- func BuildName() string
- func Bytes2string(b []byte) string
- func BytesToInt64(b []byte) int64
- func BytesToUint16(b []byte) uint16
- func BytesToUint32(b []byte) uint32
- func BytesToUint64(b []byte) uint64
- func ChangeMap(v interface{}) (map[string]interface{}, error)
- func Check(message string, zeroes int, nonce int) bool
- func CheckCreateDir(dir_path string) error
- func CheckNonce(code []byte, zeroes uint64) bool
- func DenBase64(str string) (bs []byte, err error)
- func DistinctString(list []string) []string
- func EnBase64(bs []byte) string
- func Encode(buf []byte, code uint64) ([]byte, error)
- func EncodeName(buf []byte, name string) ([]byte, error)
- func Encrypt(plantText, key []byte) ([]byte, error)
- func EncryptPrk(prkbs, key []byte) []byte
- func FilePathSplit(path string) []string
- func FileSHA3_256(path string) ([]byte, error)
- func FormatIdUtil(idInt *big.Int) string
- func FormatTimeToSecond(now time.Time) string
- func FullHighPositionZero(bs *[]byte, n int) *[]byte
- func GetAccNumber() uint64
- func GetAvailablePortForTCP(addr string) net.Listener
- func GetAvailablePortForUDP() int
- func GetDiskFreeSpace(dirPath string) (uint64, uint64, uint64, error)
- func GetHashByByte(bs []byte) string
- func GetHashForDomain(domain string) []byte
- func GetHashKey(account string) *big.Int
- func GetLocalHost() string
- func GetLocalIntenetIp() (string, bool)
- func GetNow() int64
- func GetRandNum(n int64) int64
- func GetRandomDomain() string
- func GetRandomOneInt64() int64
- func GetStopService() chan bool
- func GetTCPListener(ip string, port int) (*net.TCPListener, error)
- func GetTimeToken(class string, wait bool) (allow bool)
- func Go(f func())
- func Hash_SHA3_256(bs []byte) []byte
- func Hash_SHA3_512(bs []byte) []byte
- func IPV4Long2String(i uint32) (string, error)
- func IPV4String2Long(ip string) (uint32, error)
- func InitBuildRandomName()
- func InitLedis(dbpath string)
- func Int64ToBytes(n int64) []byte
- func IsOnlyIp(ip string) bool
- func Key16Padding(key []byte) []byte
- func LogBuildColorOutputConsole()
- func LogBuildColorOutputFile(filename string) error
- func LogBuildDefaultConsole()
- func LogBuildDefaultFile(filename string) error
- func Mkdir(path string) error
- func NewPollManager() *pollManager
- func NotifyRestart() error
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func ParseKeyToByte(prkbs []byte) []byte
- func PathExists(path string) (bool, error)
- func PprofMem(timeout time.Duration)
- func Print(findInt *big.Int)
- func PrintPanicStack()
- func RandString(strs ...string) string
- func RenameTempFile(name string) error
- func SaveFileSafe(name string, bs *[]byte) error
- func SaveJsonFile(name string, o interface{}) error
- func SetTimeToken(class string, t time.Duration)
- func StartOtherTime() error
- func StartSystemTime() error
- func StopMemProfile(memProfile, cpuProfile *os.File)
- func StopService()
- func TimeFormatToNanosecond() string
- func TimeFormatToNanosecondStr() string
- func Uint16ToBytes(n uint16) []byte
- func Uint32ToBytes(n uint32) []byte
- func Uint64ToBytes(n uint64) []byte
- func ValidCode(code uint64) bool
- func Work(message string, zeroes int) int
- type BackoffTimer
- type BackoffTimerChan
- type BufferByte
- type Cache
- type ChanDynamic
- type DBLedis
- type DecodedMultihash
- type ERROR
- type ErrInconsistentLen
- type Key
- type LedisDB
- func (this *LedisDB) AddZSet(name, member *[]byte, orderId int64) error
- func (this *LedisDB) AddZSetAutoincrId(name *[]byte, member []byte, duration int64) error
- func (this *LedisDB) CheckHashExist(hash []byte) (bool, error)
- func (this *LedisDB) CheckNullDB(key []byte) (bool, error)
- func (this *LedisDB) DelZSet(name *[]byte, min, max int64) error
- func (this *LedisDB) DelZSetAll(name *[]byte) error
- func (this *LedisDB) DelZSetByMembers(name *[]byte, members ...[]byte) error
- func (this *LedisDB) Find(txId []byte) (*[]byte, error)
- func (this *LedisDB) GetDB() *ledis.DB
- func (ldb *LedisDB) GetRangeZSet(name *[]byte, start, stop int) (*[]ledis.ScorePair, error)
- func (this *LedisDB) GetZSetAll(name *[]byte) (*[]ledis.ScorePair, error)
- func (this *LedisDB) GetZSetByMember(name *[]byte, member []byte) (int64, error)
- func (this *LedisDB) GetZSetPage(name *[]byte, min, max int64, count int) (*[]ledis.ScorePair, error)
- func (this *LedisDB) InitDB() (err error)
- func (ldb *LedisDB) LRange(key []byte, start, end int32) ([][]byte, error)
- func (this *LedisDB) Remove(id []byte) error
- func (ldb *LedisDB) Rpush(key, val []byte) (int64, error)
- func (this *LedisDB) Save(id []byte, bs *[]byte) error
- func (ldb *LedisDB) SetExpire(key *[]byte, duration int64) (int64, error)
- func (this *LedisDB) ZSetCard(name *[]byte) (n int64, err error)
- type Multihash
- type Multihashs
- type NetParams
- type NetResult
- type SyncList
- type SyncTimeFun
- type Task
- type Tick
- type Ticks
Constants ¶
const ( ERROR_CODE_success = 60000 //成功 ERROR_CODE_system_error_remote = 60001 //系统错误--远程节点 ERROR_CODE_system_error_self = 60002 //系统错误--自己节点 )
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
const AES_CTR_DEFAULT_KEY = "AES_CTR_DEFAULT_KEY" //默认密码
const (
RestartCommand = "restart" //重启参数
)
Variables ¶
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
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
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
var Log zerolog.Logger
var Name_pro []string //名称前缀 rune
var Name_suffix_long []string //名称后缀(长)
var Name_suffix_short []string //名称后缀(短)
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
var Quant *ledis.DB
Functions ¶
func AddTimetask ¶
添加一个定时任务 @tick int64 未来的某个时刻,例如(未来10秒钟后执行):time.Now().Unix()+int64(10)
func AesCTR_Decrypt ¶
解密 @key []byte 加密密码 @iv []byte 加密向量 @cipherText []byte 待解密字节
func AesCTR_Decrypt_File ¶
解密文件
func AesCTR_Encrypt ¶
加密 @key []byte 加密密码 @iv []byte 加密向量 @plainText []byte 待加密字节
func AesCTR_Encrypt_File ¶
加密文件 @key []byte 加密密码 @iv []byte 加密向量 @plainFilePath string 待加密的文件路径 @cipherFilePath string 加密后的文件保存路径
func BuildKeyToByte ¶
func CheckNonce ¶
检查hash值是否有足够多的前导零 @code string Hash值 @zeroes uint64 前导零个数
func Encode ¶
Encode a hash digest along with the specified function code. Note: the length is derived from the length of the digest itself.
func EncodeName ¶
EncodeName is like Encode() but providing a string name instead of a numeric code. See Names for allowed values.
func FormatTimeToSecond ¶
func GetDiskFreeSpace ¶
获取磁盘空间大小以及可用空间大小 @return uint64 磁盘总大小 @return uint64 磁盘可用空间大小 @return uint64 磁盘可用空间大小
func GetHashByByte ¶
func GetLocalIntenetIp ¶
获取本机能联网的ip地址 @return string 获得的ip地址 @return bool 是否能联网
func GetTimeToken ¶
func Hash_SHA3_256 ¶
func Hash_SHA3_512 ¶
func LogBuildColorOutputConsole ¶
func LogBuildColorOutputConsole()
构建为ConsoleWriter格式输出 注意不要在生产环境中使用 , ConsoleWriter 因为它会大大减慢日志记录的速度。它只是为了帮助在开发应用程序时使日志更易于阅读。您可以使用环境变量仅在开发中启用 ConsoleWriter 输出
func LogBuildColorOutputFile ¶
构建为ConsoleWriter格式输出 注意不要在生产环境中使用 , ConsoleWriter 因为它会大大减慢日志记录的速度。它只是为了帮助在开发应用程序时使日志更易于阅读。您可以使用环境变量仅在开发中启用 ConsoleWriter 输出
func NewPollManager ¶
func NewPollManager() *pollManager
func PKCS7Padding ¶
func ParseKeyToByte ¶
-----BEGIN EC PRIVATE KEY----- MIHcAgEBBEIAJuVZ2ujd64R6iA3mJ2Iuaorwc3kUXihcLvF51nuF8MHE82ZobU4k JBwOjjFX1jjZGDAyiIgXpD9HXtfIWCpIksigBwYFK4EEACOhgYkDgYYABAB7ZnsN kzgg7JrVxohq2FOxRpA+bUsVsxHKHRur0ezttNRu7ldR36fGgyztoplyUltUndID 7EEi2o9z2E4q99ozOgHwbHnx5WROGYtwvdwDQtvHnCynzO7eixMFZ8pKLddz7YLs hm8sApO1ZneSDMMBoKhtlX4+pywXZ91WxEfOY/GXlA== -----END EC PRIVATE KEY-----
将这种格式的[]byte,去掉头和尾后拼接中间的字符
func SaveFileSafe ¶
保存文件 保存文件步骤: 1.创建临时文件 2.删除目标文件 3.修改临时文件名称为目标文件名称
func SetTimeToken ¶
func StartOtherTime ¶
func StartOtherTime() error
func StartSystemTime ¶
func StartSystemTime() error
func StopMemProfile ¶
func TimeFormatToNanosecond ¶
func TimeFormatToNanosecond() string
func TimeFormatToNanosecondStr ¶
func TimeFormatToNanosecondStr() string
Types ¶
type BackoffTimer ¶
type BackoffTimer struct {
// contains filtered or unexported fields
}
func (*BackoffTimer) Wait ¶
func (this *BackoffTimer) Wait() time.Duration
等待时间 @return time.Duration 等待的时间
type BackoffTimerChan ¶
type BackoffTimerChan struct {
// contains filtered or unexported fields
}
func NewBackoffTimerChan ¶
func NewBackoffTimerChan(n ...time.Duration) *BackoffTimerChan
间隔n秒后发送一个信号
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) Length ¶
func (this *BufferByte) Length() (n 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 ¶
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) RemoveOldest ¶
func (c *Cache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
type ChanDynamic ¶
type ChanDynamic struct {
// contains filtered or unexported fields
}
动态大小的管道
func (*ChanDynamic) Add ¶
func (this *ChanDynamic) Add(one interface{})
func (*ChanDynamic) Get ¶
func (this *ChanDynamic) Get(contextRoot context.Context) interface{}
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 ¶
func ParseERROR ¶
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 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 (*LedisDB) AddZSetAutoincrId ¶
添加一个数据到zset,id为自增长
func (*LedisDB) CheckHashExist ¶
检查key是否存在 @return bool true:存在;false:不存在;
func (*LedisDB) DelZSetByMembers ¶
删除zset中多个members
func (*LedisDB) GetRangeZSet ¶
* 查询根据 start stop 查询返回zset
func (*LedisDB) GetZSetAll ¶
添加一个数据到zset
func (*LedisDB) GetZSetByMember ¶
获取一个member的下标,如果不存在,则返回-1
func (*LedisDB) GetZSetPage ¶
func (this *LedisDB) GetZSetPage(name *[]byte, min, max int64, count int) (*[]ledis.ScorePair, error)
添加一个数据到zset
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 FromB58String ¶
FromB58String parses a B58-encoded multihash.
func FromHexString ¶
FromHexString parses a hex-encoded multihash.
type Multihashs ¶
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 NetResult ¶
type NetResult struct { Version uint64 //协议版本号 Code uint64 //错误编码 Msg string //错误信息 Data []byte //返回参数 }
网络返回参数
type SyncList ¶
type SyncList struct {
// contains filtered or unexported fields
}
func NewSyncList ¶
func NewSyncList() *SyncList
type SyncTimeFun ¶
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Source Files
¶
- acc.go
- aes.go
- aes_ctr.go
- backoff_timer.go
- binary.go
- build_random_name.go
- bytebuffer_pool.go
- chan_cache.go
- closeservice.go
- common.go
- crashlog.go
- diskinfo_linux.go
- ecdsa.go
- encoding.go
- error.go
- file.go
- goroutine.go
- hash.go
- hashcash.go
- json.go
- ledisdb.go
- log.go
- lru.go
- merkle.go
- multihash.go
- multihashs.go
- net.go
- net_params_result.go
- pprof.go
- rand.go
- restart.go
- s256.go
- string.go
- sync_list.go
- time.go
- time_sync.go
- timetask.go
- timetaskapi.go
- utils.go
- vote.go