base

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 20 Imported by: 6

Documentation

Index

Constants

View Source
const (
	Bit8              = 8
	Bit16             = 16
	Bit32             = 32
	Bit64             = 64
	Bit128            = 128
	MAX_PACKET        = 1 * 1024 * 1024
	MAX_CLIENT_PACKET = 10 * 1024
)
View Source
const (
	NONE_ERROR      = iota
	VERSION_ERROR   //版本不正确
	ACCOUNT_NOEXIST //账号不存在
	PASSWORD_ERROR  //密码不正确
)
View Source
const (
	PATH = "log"
)
View Source
const (
	REPLICASNUM = 5
)
View Source
const (
	WorkeridMax = workeridMax //集群自增量
)

Variables

View Source
var ErrEmptyRing = errors.New("empty ring")

ErrEmptyRing is the error returned when trying to get an element when nothing has been added to hash.

View Source
var RAND = Rand{rand.New(rand.NewSource(time.Now().UnixNano()))}
View Source
var (
	SEVERNAME string
)
View Source
var (
	UUID = ISnowflake(&Snowflake{})
)

Functions

func Abs

func Abs(x float32) float32

func Assert

func Assert(x bool, y string)

func BIT

func BIT(x interface{}) interface{}

func BIT64

func BIT64(x interface{}) interface{}

func Bool

func Bool(str string) bool

func BytesToFloat32

func BytesToFloat32(data []byte) float32

func BytesToFloat64

func BytesToFloat64(data []byte) float64

func BytesToInt

func BytesToInt(data []byte) int

字节转换成整形

func BytesToInt16

func BytesToInt16(data []byte) int16

字节转换成为int16

func BytesToInt64

func BytesToInt64(data []byte) int64

func ChechErr

func ChechErr(err error)

func Clamp

func Clamp(val, low, high int) int

func Float32

func Float32(str string) float32

func Float32ToByte

func Float32ToByte(val float32) []byte

转化float

func Float64

func Float64(str string) float64

func Float64ToByte

func Float64ToByte(val float64) []byte

转化float64

func GetClassName

func GetClassName(rType reflect.Type) string

func GetDBTime

func GetDBTime(strTime string) *time.Time

func GetLanAddr added in v0.0.5

func GetLanAddr(ip string) string

func Htonl

func Htonl(n uint64) []byte

func Htons

func Htons(n uint16) []byte

func Int

func Int(str string) int

-----------string strconv type-------------//

func Int16ToBytes

func Int16ToBytes(val int16) []byte

整形16转换成字节

func Int64

func Int64(str string) int64

func Int64ToBytes

func Int64ToBytes(val int64) []byte

转化64位

func IntToBytes

func IntToBytes(val int) []byte

整形转换成字节

func IntToInt32

func IntToInt32(val []int) []int32

[]int转[]int32

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func ParseTag

func ParseTag(sf reflect.StructField, tag string) map[string]string

func ParseUUID

func ParseUUID(id int64) (ts int64, workerId int64, seq int64)

func PathExists

func PathExists(path string) bool

func ReadConf added in v0.0.5

func ReadConf(path string, data interface{}) bool

func SetTcpEnd

func SetTcpEnd(buff []byte) []byte

func Time

func Time(str string) int64

func ToHash

func ToHash(str string) uint32

func TraceCode

func TraceCode(code ...interface{})

输出错误,跟踪代码

Types

type BitStream

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

func NewBitStream

func NewBitStream(buf []byte, nLen int) *BitStream

func (*BitStream) BuildPacketStream

func (b *BitStream) BuildPacketStream(buffer []byte, writeSize int) bool

func (*BitStream) GetBuffer

func (b *BitStream) GetBuffer() []byte

func (*BitStream) GetBytePtr

func (b *BitStream) GetBytePtr() []byte

func (*BitStream) GetCurPos

func (b *BitStream) GetCurPos() int

func (*BitStream) GetPosition

func (b *BitStream) GetPosition() int

func (*BitStream) GetReadByteSize

func (b *BitStream) GetReadByteSize() int

func (*BitStream) GetStreamSize

func (b *BitStream) GetStreamSize() int

func (*BitStream) ReadBits

func (b *BitStream) ReadBits(bitCount int) []byte

func (*BitStream) ReadFlag

func (b *BitStream) ReadFlag() bool

func (*BitStream) ReadFloat

func (b *BitStream) ReadFloat() float32

func (*BitStream) ReadFloat64

func (b *BitStream) ReadFloat64() float64

func (*BitStream) ReadInt

func (b *BitStream) ReadInt(bitCount int) int

func (*BitStream) ReadInt64

func (b *BitStream) ReadInt64(bitCount int) int64

func (*BitStream) ReadString

func (b *BitStream) ReadString() string

func (*BitStream) SetPosition

func (b *BitStream) SetPosition(pos int) bool

func (*BitStream) WriteBits

func (b *BitStream) WriteBits(bitPtr []byte, bitCount int)

func (*BitStream) WriteFlag

func (b *BitStream) WriteFlag(value bool) bool

func (*BitStream) WriteFloat

func (b *BitStream) WriteFloat(value float32)

func (*BitStream) WriteFloat64

func (b *BitStream) WriteFloat64(value float64)

func (*BitStream) WriteInt

func (b *BitStream) WriteInt(value int, bitCount int)

func (*BitStream) WriteInt64

func (b *BitStream) WriteInt64(value int64, bitCount int)

func (*BitStream) WriteString

func (b *BitStream) WriteString(value string)

type Dh added in v0.0.5

type Dh struct {
	Y1 big.Int //自己公钥
	Y2 big.Int //对方公钥
	// contains filtered or unexported fields
}

func (*Dh) ExchangePubk added in v0.0.5

func (d *Dh) ExchangePubk(key int64)

func (*Dh) Init added in v0.0.5

func (d *Dh) Init()

func (*Dh) PubKey added in v0.0.5

func (d *Dh) PubKey() int64

func (*Dh) ShareKey added in v0.0.5

func (d *Dh) ShareKey() int64

type HashRing

type HashRing struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HashRing holds the information about the members of the consistent hash ring.

func NewHashRing

func NewHashRing() *HashRing

New creates a new HashRing( object with a default setting of 20 replicas for each entry. To change the number of replicas, set NumberOfReplicas before adding entries.

func (*HashRing) Add

func (h *HashRing) Add(elt string)

Add inserts a string element in the consistent hash.

func (*HashRing) Get

func (h *HashRing) Get(name string) (error, string)

Get returns an element close to where name hashes to in the ring.

func (*HashRing) Get64

func (h *HashRing) Get64(val int64) (error, uint32)

func (*HashRing) HasMember

func (h *HashRing) HasMember(elt string) bool

func (*HashRing) Members

func (h *HashRing) Members() []string

func (*HashRing) Remove

func (h *HashRing) Remove(elt string)

Remove removes an element from the hash.

type IBitStream

type IBitStream interface {
	BuildPacketStream([]byte, int) bool

	GetBuffer() []byte
	GetBytePtr() []byte
	GetReadByteSize() int
	GetCurPos() int
	GetPosition() int
	GetStreamSize() int
	SetPosition(int) bool

	WriteBits([]byte, int)
	ReadBits(int) []byte
	WriteInt(int, int)
	ReadInt(int) int
	ReadFlag() bool
	WriteFlag(bool) bool
	WriteString(string)
	ReadString() string

	WriteInt64(int64, int)
	ReadInt64(int) int64
	WriteFloat(float32)
	ReadFloat() float32
	WriteFloat64(float64)
	ReadFloat64() float64
	// contains filtered or unexported methods
}

type IDh added in v0.0.5

type IDh interface {
	Init()

	ExchangePubk(key int64) //交换公钥
	PubKey() int64          //公钥
	ShareKey() int64        //生成共享密钥
	// contains filtered or unexported methods
}

type IHashRing

type IHashRing interface {
	Add(elt string)
	Remove(elt string)
	HasMember(elt string) bool
	Members() []string
	Get(name string) (error, string)
	Get64(val int64) (error, uint32)
}

type ILog

type ILog interface {
	Init(string) bool
	Write(LG_TYPE)
	WriteFile(LG_TYPE)
	Println(...interface{})
	Print(...interface{})
	Printf(string, ...interface{})
	Fatalln(...interface{})
	Fatal(...interface{})
	Fatalf(string, ...interface{})
}

type ISnowflake

type ISnowflake interface {
	Init(workerid int64)
	UUID() int64
}

type IStuHashRing

type IStuHashRing interface {
	Init(endpoints []string)
	Get(val int64) (error, uint32)
}

use for stubring

type IWorkIdQue

type IWorkIdQue interface {
	Init(int)
	Add(string) int
	Del(string) int
}

type LG_TYPE

type LG_TYPE int
const (
	LG_WARN  LG_TYPE = iota
	LG_ERROR LG_TYPE = iota
	LG_MAX   LG_TYPE = iota
)

type Log

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

func (*Log) Fatal

func (this *Log) Fatal(v1 ...interface{})

func (*Log) Fatalf

func (this *Log) Fatalf(format string, params ...interface{})

func (*Log) Fatalln

func (this *Log) Fatalln(v1 ...interface{})

func (*Log) GetSuffix

func (this *Log) GetSuffix(nType LG_TYPE) string

func (*Log) Init

func (this *Log) Init(fileName string) bool

func (*Log) Print

func (this *Log) Print(v1 ...interface{})

func (*Log) Printf

func (this *Log) Printf(format string, params ...interface{})

func (*Log) Println

func (this *Log) Println(v1 ...interface{})

func (*Log) Write

func (this *Log) Write(nType LG_TYPE)

func (*Log) WriteFile

func (this *Log) WriteFile(nType LG_TYPE)

type Rand

type Rand struct {
	*rand.Rand
}

func (*Rand) RandF

func (r *Rand) RandF(i float32, n float32) float32

func (*Rand) RandI

func (r *Rand) RandI(i int, n int) int

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Snowflake) Init

func (s *Snowflake) Init(workerid int64)

func (*Snowflake) UUID

func (s *Snowflake) UUID() int64

Generate creates and returns a unique snowflake ID

type StubHashRing

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

HashRing holds the information about the members of the consistent hash ring.

func (*StubHashRing) Get

func (h *StubHashRing) Get(val int64) (error, uint32)

func (*StubHashRing) Init

func (h *StubHashRing) Init(endpoints []string)

Add inserts a string element in the consistent hash.

type WorkIdQue

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

func (*WorkIdQue) Add

func (w *WorkIdQue) Add(val string) int

func (*WorkIdQue) Del

func (w *WorkIdQue) Del(val string) int

func (*WorkIdQue) Init

func (w *WorkIdQue) Init(id int)

Directories

Path Synopsis
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.

Jump to

Keyboard shortcuts

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