base

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NONE_ERROR      = iota
	VERSION_ERROR   //版本不正确
	ACCOUNT_NOEXIST //账号不存在
	PASSWORD_ERROR  //密码不正确
)
View Source
const (
	Bit8              = 8
	Bit16             = 16
	Bit32             = 32
	Bit64             = 64
	Bit128            = 128
	MAX_PACKET        = 1 * 1024 * 1024 //1MB
	MAX_CLIENT_PACKET = 10 * 1024       //10KB
)
View Source
const (
	INT_MAX       = int(2147483647)
	TCP_HEAD_SIZE = 4    //解决tpc粘包半包,包头固定长度
	TCP_END       = "💞♡" //解决tpc粘包半包,特殊结束标志,pb采用Varint编码高位有特殊含义
)
View Source
const (
	DATA_END        = "data_end"
	DATA_END_LENGTH = len(DATA_END) //data结束标记
)
View Source
const (
	DType_none        = iota
	DType_String      = iota
	DType_Enum        = iota
	DType_S8          = iota
	DType_S16         = iota
	DType_S32         = iota
	DType_F32         = iota
	DType_F64         = iota
	DType_S64         = iota
	DType_StringArray = iota
	DType_S8Array     = iota
	DType_S16Array    = iota
	DType_S32Array    = iota
	DType_F32Array    = iota
	DType_F64Array    = iota
	DType_S64Array    = iota
)

datatype

View Source
const (
	INTERVAL_DAY     = iota //当前时间的第二天
	INTERVAL_WEEK    = iota //当前时间的下周一
	INTERVAL_MONTH   = iota //当前时间的下一月第一天)
	INTERVAL_YEAR    = iota //当前时间的下一年第一天)
	TIME_SET_MAX_VAL = iota //类型最大值
)
View Source
const (
	BUILD_NO = "1,5,1,1"
)
View Source
const (
	CRYPT_BUFFER_SIZE = 0x500
)
View Source
const (
	PATH = "log"
)
View Source
const (
	REPLICASNUM = 5
)
View Source
const (
	WorkeridMax = workeridMax //集群自增量
)

* Snowflake * * 1 42 54 64 * +-----------------------------------------------+----------------+---------------+ * | timestamp(ms) | workerid | sequence | * +-----------------------------------------------+----------------+---------------+ * | 0000000000 0000000000 0000000000 0000000000 0 | 0000000000 00 | 0000000000 | * +-----------------------------------------------+----------------+---------------+ * * 1. 41位时间截(毫秒级),注意这是时间截的差值(当前时间截 - 开始时间截)。可以使用约69年: (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69 * 2. 12位数据机器位,可以部署在4096个节点 * 3. 10位序列,毫秒内的计数,同一机器,同一时间截并发1024个序号

Variables

View Source
var (
	SEVERNAME      string
	TCP_END_LENGTH = len([]byte(TCP_END)) //tcp结束标志长度
)
View Source
var (
	CryptBuffer []uint32
)
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.New(rand.NewSource(time.Now().UnixNano()))
View Source
var (
	UUID = ISnowflake(&Snowflake{})
)

Functions

func Abs

func Abs(x float32) float32

func Assert

func Assert(x bool, y string)

func Ast

func Ast(fileName string) map[int]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[T orderKey](val, low, high T) T

func CopyMap added in v1.9.9

func CopyMap[M ~map[K]V, K comparable, V any](m M) M

func CopySlice added in v1.9.9

func CopySlice[M ~[]V, V any](m M) M

func DBERROR added in v1.9.9

func DBERROR(msg string, err error)

func DecryptName1

func DecryptName1(strName string) uint32

func DecryptName2

func DecryptName2(strName string) uint32

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 Get

func Get(url string, params ...Kv) ([]byte, error)

发送GET请求 url:请求地址 response:请求返回的内容

func GetAvlHeight

func GetAvlHeight(tree *AvlBitTree) int

func GetClassName

func GetClassName(rType reflect.Type) string

func GetDBTime

func GetDBTime(strTime string) *time.Time

func GetLanAddr

func GetLanAddr(ip string) string

func GetMessageCode

func GetMessageCode(strName string, m1 *uint32, m2 *uint32)

func GetMessageCode1

func GetMessageCode1(strName string) uint32

func GetMessageCode2

func GetMessageCode2(strName string) uint32

func GetNextTime

func GetNextTime(intervalType int) time.Time

func Htonl

func Htonl(n uint64) []byte

func Htons

func Htons(n uint16) []byte

func IFAssert

func IFAssert(x bool, y string)

func InsertSort

func InsertSort(arr []int)

-----------insert sort----------//

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 Keys added in v1.9.9

func Keys[M ~map[K]V, K comparable, V any](m M) []K

func LoadData

func LoadData(obj interface{}, file *DataFile) bool

--- struct to data

func MD5

func MD5(str string) string

func Max

func Max[T orderKey](x, y T) T

func MaxHeap

func MaxHeap(arr []int)

func MiddleAvlPrint

func MiddleAvlPrint(tree *AvlBitTree)

func MiddlePrint

func MiddlePrint(tree *BitTree)

func Min

func Min[T orderKey](x, y T) T

func MinHeap

func MinHeap(arr []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 PopHeap

func PopHeap(arr []int, bMax bool) []int

func Post

func Post(url string, data []byte, contentType string) ([]byte, error)

发送POST请求 url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json content:请求放回的内容

func PrepareCryptBuffer

func PrepareCryptBuffer()

func QuickSort

func QuickSort(arr []int, left int, right int)

-----------quick sort----------//

func QuickSort2

func QuickSort2(arr []int, left, right int)

-----------quick2 sort----------//

func RandF added in v1.9.6

func RandF[T ~float32 | ~float64](i T, n T) T

func RandI added in v1.9.6

func RandI[T RandType](i T, n T) T

func ReadConf

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

func SelectSort

func SelectSort(arr []int)

------------select sort--------//

func SetTcpEnd

func SetTcpEnd(buff []byte) []byte

func Time

func Time(str string) int64

func ToHash

func ToHash(str string) uint32

func ToString

func ToString(value interface{}) string

--------------------------------------------// ToString converts a value to string.

func TraceCode

func TraceCode(code ...interface{})

输出错误,跟踪代码

func UInt64 added in v1.9.9

func UInt64(str string) uint64

func Values added in v1.9.9

func Values[M ~map[K]V, K comparable, V any](m M) []V

~map //~这里所有以map为基础类型的都能被约束到

func WalkDir

func WalkDir(dirpath string, filesVec *vector.Vector[os.FileInfo])

---------遍历子目录------------//

Types

type AvlBitTree

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

--------------avltree---------//

func DeleteAvlTree

func DeleteAvlTree(tree *AvlBitTree, data int) *AvlBitTree

func InsertAvlBitTree

func InsertAvlBitTree(tree *AvlBitTree, data int) *AvlBitTree

func LR_Rorate

func LR_Rorate(tree *AvlBitTree, root **AvlBitTree) *AvlBitTree

func L_Rorate

func L_Rorate(tree *AvlBitTree, root **AvlBitTree) *AvlBitTree

func RL_Rorate

func RL_Rorate(tree *AvlBitTree, root **AvlBitTree) *AvlBitTree

func R_Rorate

func R_Rorate(tree *AvlBitTree, root **AvlBitTree) *AvlBitTree

func (*AvlBitTree) Equal

func (a *AvlBitTree) Equal(data int) bool

func (*AvlBitTree) Less

func (a *AvlBitTree) Less(data int) bool

type BitMap

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

func NewBitMap

func NewBitMap(size int) *BitMap

func (*BitMap) Clear

func (b *BitMap) Clear(index int)

func (*BitMap) ClearAll

func (b *BitMap) ClearAll()

func (*BitMap) Init

func (b *BitMap) Init(size int)

func (*BitMap) Set

func (b *BitMap) Set(index int)

func (*BitMap) Test

func (b *BitMap) Test(index int) bool

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 BitTree

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

-----------bittreee-------------------//

func DeleteTree

func DeleteTree(tree *BitTree, data int) *BitTree

func InsertBitTree

func InsertBitTree(tree *BitTree, data int) *BitTree

func (*BitTree) Equal

func (b *BitTree) Equal(data int) bool

func (*BitTree) Less

func (b *BitTree) Less(data int) bool

type Data

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

func (*Data) Enum

func (d *Data) Enum(datacol string) int

func (*Data) Float32

func (d *Data) Float32(datacol string) float32

func (*Data) Float32Array

func (d *Data) Float32Array(datacol string) []float32

func (*Data) Float64

func (d *Data) Float64(datacol string) float64

func (*Data) Float64Array

func (d *Data) Float64Array(datacol string) []float64

func (*Data) Int

func (d *Data) Int(datacol string) int

func (*Data) Int16

func (d *Data) Int16(datacol string) int16

func (*Data) Int16Array

func (d *Data) Int16Array(datacol string) []int16

func (*Data) Int64

func (d *Data) Int64(datacol string) int64

func (*Data) Int64Array

func (d *Data) Int64Array(datacol string) []int64

func (*Data) Int8

func (d *Data) Int8(datacol string) int8

func (*Data) Int8Array

func (d *Data) Int8Array(datacol string) []int8

func (*Data) IntArray

func (d *Data) IntArray(datacol string) []int

func (*Data) String

func (d *Data) String(datacol string) string

***************************

Data funciton

***************************

func (*Data) StringArray

func (d *Data) StringArray(datacol string) []string

type DataFile

type DataFile struct {
	RecordNum int //记录数量
	ColumNum  int //列数量
	// contains filtered or unexported fields
}

func (*DataFile) GetData

func (d *DataFile) GetData(data *Data) bool

***************************

格式:
头文件:
1、总记录数(int)
2、总字段数(int)
字段格式:
1、字段长度(int)
2、字读数据类型(int->2,string->1,enum->3,float->4)
3、字段内容(int,string)

************************

func (*DataFile) ReadDataFile

func (d *DataFile) ReadDataFile(fileName string) bool

func (*DataFile) ReadDataInit

func (d *DataFile) ReadDataInit()

type Dh

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

func (*Dh) ExchangePubk

func (d *Dh) ExchangePubk(key int64)

func (*Dh) Init

func (d *Dh) Init()

func (*Dh) PubKey

func (d *Dh) PubKey() int64

func (*Dh) ShareKey

func (d *Dh) ShareKey() int64

type Fsm added in v1.9.9

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

状态机

func (*Fsm) GetPreState added in v1.9.9

func (f *Fsm) GetPreState() int

获取前面的一个状态

func (*Fsm) GetState added in v1.9.9

func (f *Fsm) GetState() int

func (*Fsm) Init added in v1.9.9

func (f *Fsm) Init(_maxState int)

func (*Fsm) SetState added in v1.9.9

func (f *Fsm) SetState(state int)

func (*Fsm) SetStateHandle added in v1.9.9

func (f *Fsm) SetStateHandle(state int, st *State)

func (*Fsm) Update added in v1.9.9

func (f *Fsm) Update()

type FsmHandle added in v1.9.9

type FsmHandle func()

状态机

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 IAvlBitTree

type IAvlBitTree interface {
	Less(int) bool
	Equal(int) bool
}

--------------avltree---------//

type IBitMap

type IBitMap interface {
	Init(size int)
	Set(index int)       //设置位
	Test(index int) bool //位是否被设置
	Clear(index int)     //清楚位
	ClearAll()
}

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 IBitTree

type IBitTree interface {
	Less(int) bool
	Equal(int) bool
}

-----------bittreee-------------------//

type IDateFile

type IDateFile interface {
	ReadDataFile(string) bool
	GetData(*Data) bool
	ReadDataInit()
}

type IDh

type IDh interface {
	Init()

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

type IFsm added in v1.9.9

type IFsm interface {
	Init(int)
	SetStateHandle(state int, st *State)
	SetState(int)
	GetState() int
	GetPreState() int
	Update()
}

状态机

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 IVersion

type IVersion interface {
	IsAcceptableBuildVersion(string) bool
	Init()
}

type IWorkIdQue

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

type Kv

type Kv struct {
	Key string
	Val interface{}
}

type LG_TYPE

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

type Locker

type Locker struct {
	sync.Locker
}

type Log

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

func (*Log) Fatal

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

func (*Log) Fatalf

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

func (*Log) Fatalln

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

func (*Log) GetSuffix

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

func (*Log) Init

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

func (*Log) Print

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

func (*Log) Printf

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

func (*Log) Println

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

func (*Log) Write

func (l *Log) Write(nType LG_TYPE)

func (*Log) WriteFile

func (l *Log) WriteFile(nType LG_TYPE)

type Rand

type Rand struct {
	*rand.Rand
}

type RandType added in v1.9.6

type RandType interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 |
		~uint32 | ~uint64
}

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 State added in v1.9.9

type State struct {
	OnEnter FsmHandle
	OnExec  FsmHandle
	OnExit  FsmHandle
}

状态机

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 Version

type Version struct {
	// contains filtered or unexported fields
}
var (
	VERSION Version
)

func (*Version) Init

func (v *Version) Init()

func (*Version) IsAcceptableBuildVersion

func (v *Version) IsAcceptableBuildVersion(version string) bool

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)

----------WorkIdQue----------//

Directories

Path Synopsis
rpc
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