internal

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermessageDeflate       = "permessage-deflate"
	ServerMaxWindowBits     = "server_max_window_bits"
	ClientMaxWindowBits     = "client_max_window_bits"
	ServerNoContextTakeover = "server_no_context_takeover"
	ClientNoContextTakeover = "client_no_context_takeover"
	EQ                      = "="
)
View Source
const (
	ThresholdV1 = 125
	ThresholdV2 = math.MaxUint16
	ThresholdV3 = math.MaxUint64
)
View Source
const MagicNumber = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
View Source
const Nil = 0

Variables

View Source
var (
	SecWebSocketVersion    = Pair{"Sec-WebSocket-Version", "13"}
	SecWebSocketKey        = Pair{"Sec-WebSocket-Key", ""}
	SecWebSocketExtensions = Pair{"Sec-WebSocket-Extensions", "permessage-deflate; server_no_context_takeover; client_no_context_takeover"}
	Connection             = Pair{"Connection", "Upgrade"}
	Upgrade                = Pair{"Upgrade", "websocket"}
	SecWebSocketAccept     = Pair{"Sec-WebSocket-Accept", ""}
	SecWebSocketProtocol   = Pair{"Sec-WebSocket-Protocol", ""}
)
View Source
var (
	AlphabetNumeric = &RandomString{
		layout: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
		r:      rand.New(rand.NewSource(time.Now().UnixNano())),
		mu:     sync.Mutex{},
	}

	Numeric = &RandomString{
		layout: "0123456789",
		r:      rand.New(rand.NewSource(time.Now().UnixNano())),
		mu:     sync.Mutex{},
	}
)

Functions

func BinaryPow

func BinaryPow(n int) int

func BufferReset

func BufferReset(b *bytes.Buffer, p []byte)

BufferReset 重置buffer底层切片 修改后面的属性一定要加偏移量!!!

func CheckEncoding

func CheckEncoding(opcode uint8, payload []byte) bool

func ComputeAcceptKey

func ComputeAcceptKey(challengeKey string) string

func Errors

func Errors(funcs ...func() error) error

func FnvNumber

func FnvNumber[T Integer](x T) uint64

func FnvString

func FnvString(s string) uint64

func GetIntersectionElem

func GetIntersectionElem(a, b []string) string

GetIntersectionElem 获取两个数组交集中的一个元素

func HttpHeaderContains

func HttpHeaderContains(a, b string) bool

func HttpHeaderEqual

func HttpHeaderEqual(a, b string) bool

func InCollection

func InCollection(elem string, elems []string) bool

func IsSameSlice

func IsSameSlice[T comparable](a, b []T) bool

func IsZero

func IsZero[T comparable](v T) bool

IsZero 零值判断

func MaskByByte

func MaskByByte(content []byte, key []byte)

func MaskXOR

func MaskXOR(b []byte, key []byte)

func Max

func Max(a, b int) int

func MethodExists

func MethodExists(in any, method string) (reflect.Value, bool)

MethodExists if nil return false

func Min

func Min(a, b int) int

func NewMaskKey

func NewMaskKey() [4]byte

func ReadN

func ReadN(reader io.Reader, data []byte) error

ReadN 精准地读取len(data)个字节, 否则返回错误

func SelectValue

func SelectValue[T any](ok bool, a, b T) T

func Split

func Split(s string, sep string) []string

Split 分割字符串(空值将会被过滤掉)

func StringToBytes

func StringToBytes(s string) []byte

func ToBinaryNumber

func ToBinaryNumber[T Integer](n T) T

func WithDefault

func WithDefault[T comparable](rawValue, newValue T) T

WithDefault 如果原值为零值, 返回新值, 否则返回原值

func WriteN

func WriteN(writer io.Writer, content []byte) error

Types

type BufferPool

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

func NewBufferPool

func NewBufferPool(left, right uint32) *BufferPool

NewBufferPool Creating a memory pool Left, right indicate the interval range of the memory pool, they will be transformed into pow(2,n)。 Below left, Get method will return at least left bytes; above right, Put method will not reclaim the buffer.

func (*BufferPool) Get

func (p *BufferPool) Get(n int) *bytes.Buffer

Get Fetch a buffer from the memory pool, of at least n bytes

func (*BufferPool) Put

func (p *BufferPool) Put(b *bytes.Buffer)

Put Return buffer to memory pool

type Buffers

type Buffers [][]byte

func (Buffers) CheckEncoding

func (b Buffers) CheckEncoding(enabled bool, opcode uint8) bool

func (Buffers) Len

func (b Buffers) Len() int

func (Buffers) WriteTo

func (b Buffers) WriteTo(w io.Writer) (int64, error)

WriteTo 可重复写

type Bytes

type Bytes []byte

func (Bytes) CheckEncoding

func (b Bytes) CheckEncoding(enabled bool, opcode uint8) bool

func (Bytes) Len

func (b Bytes) Len() int

func (Bytes) WriteTo

func (b Bytes) WriteTo(w io.Writer) (int64, error)

WriteTo 可重复写

type Deque

type Deque[T any] struct {
	// contains filtered or unexported fields
}

Deque 可以不使用New函数, 声明为值类型自动初始化

func New

func New[T any](capacity int) *Deque[T]

New 创建双端队列

func (*Deque[T]) Back

func (c *Deque[T]) Back() *Element[T]

func (*Deque[T]) Clone

func (c *Deque[T]) Clone() *Deque[T]

func (*Deque[T]) Front

func (c *Deque[T]) Front() *Element[T]

func (*Deque[T]) Get

func (c *Deque[T]) Get(addr Pointer) *Element[T]

func (*Deque[T]) InsertAfter

func (c *Deque[T]) InsertAfter(value T, mark Pointer) *Element[T]

func (*Deque[T]) InsertBefore

func (c *Deque[T]) InsertBefore(value T, mark Pointer) *Element[T]

func (*Deque[T]) Len

func (c *Deque[T]) Len() int

func (*Deque[T]) MoveToBack

func (c *Deque[T]) MoveToBack(addr Pointer)

func (*Deque[T]) MoveToFront

func (c *Deque[T]) MoveToFront(addr Pointer)

func (*Deque[T]) PopBack

func (c *Deque[T]) PopBack() (value T)

func (*Deque[T]) PopFront

func (c *Deque[T]) PopFront() (value T)

func (*Deque[T]) PushBack

func (c *Deque[T]) PushBack(value T) *Element[T]

func (*Deque[T]) PushFront

func (c *Deque[T]) PushFront(value T) *Element[T]

func (*Deque[T]) Range

func (c *Deque[T]) Range(f func(ele *Element[T]) bool)

func (*Deque[T]) Remove

func (c *Deque[T]) Remove(addr Pointer)

func (*Deque[T]) Reset

func (c *Deque[T]) Reset()

Reset 重置

func (*Deque[T]) Update

func (c *Deque[T]) Update(addr Pointer, value T)

type Element

type Element[T any] struct {
	// contains filtered or unexported fields
}

func (*Element[T]) Addr

func (c *Element[T]) Addr() Pointer

func (*Element[T]) Next

func (c *Element[T]) Next() Pointer

func (*Element[T]) Prev

func (c *Element[T]) Prev() Pointer

func (*Element[T]) Value

func (c *Element[T]) Value() T

type Error

type Error struct {
	Err  error
	Code StatusCode
}

func NewError

func NewError(code StatusCode, err error) *Error

func (*Error) Error

func (c *Error) Error() string

type Integer

type Integer interface {
	int | int64 | int32 | uint | uint64 | uint32
}

type NetConn

type NetConn interface {
	NetConn() net.Conn
}

type Pair

type Pair struct {
	Key string
	Val string
}

type Payload

type Payload interface {
	io.WriterTo
	Len() int
	CheckEncoding(enabled bool, opcode uint8) bool
}

type Pointer

type Pointer uint32

func (Pointer) IsNil

func (c Pointer) IsNil() bool

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](f func() T) *Pool[T]

func (*Pool[T]) Get

func (c *Pool[T]) Get() T

func (*Pool[T]) Put

func (c *Pool[T]) Put(v T)

type RandomString

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

func (*RandomString) Generate

func (c *RandomString) Generate(n int) []byte

func (*RandomString) Intn

func (c *RandomString) Intn(n int) int

func (*RandomString) Uint32

func (c *RandomString) Uint32() uint32

func (*RandomString) Uint64

func (c *RandomString) Uint64() uint64

type Stack

type Stack[T any] []T

func (*Stack[T]) Len

func (c *Stack[T]) Len() int

Len 获取元素数量

func (*Stack[T]) Pop

func (c *Stack[T]) Pop() T

Pop 弹出元素

func (*Stack[T]) Push

func (c *Stack[T]) Push(v T)

Push 追加元素

type StatusCode

type StatusCode uint16
const (
	// CloseNormalClosure 正常关闭; 无论为何目的而创建, 该链接都已成功完成任务.
	CloseNormalClosure StatusCode = 1000

	// CloseGoingAway 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开.
	CloseGoingAway StatusCode = 1001

	// CloseProtocolError 由于协议错误而中断连接.
	CloseProtocolError StatusCode = 1002

	// CloseUnsupported 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据).
	CloseUnsupported StatusCode = 1003

	// CloseNoStatusReceived 保留. 表示没有收到预期的状态码.
	CloseNoStatusReceived StatusCode = 1005

	// CloseAbnormalClosure 保留. 用于期望收到状态码时连接非正常关闭 (也就是说, 没有发送关闭帧).
	CloseAbnormalClosure StatusCode = 1006

	// CloseUnsupportedData 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据).
	CloseUnsupportedData StatusCode = 1007

	// ClosePolicyViolation 由于收到不符合约定的数据而断开连接. 这是一个通用状态码, 用于不适合使用 1003 和 1009 状态码的场景.
	ClosePolicyViolation StatusCode = 1008

	// CloseMessageTooLarge 由于收到过大的数据帧而断开连接.
	CloseMessageTooLarge StatusCode = 1009

	// CloseMissingExtension 客户端期望服务器商定一个或多个拓展, 但服务器没有处理, 因此客户端断开连接.
	CloseMissingExtension StatusCode = 1010

	// CloseInternalServerErr 客户端由于遇到没有预料的情况阻止其完成请求, 因此服务端断开连接.
	CloseInternalServerErr StatusCode = 1011

	// CloseServiceRestart 服务器由于重启而断开连接. [Ref]
	CloseServiceRestart StatusCode = 1012

	// CloseTryAgainLater 服务器由于临时原因断开连接, 如服务器过载因此断开一部分客户端连接. [Ref]
	CloseTryAgainLater StatusCode = 1013

	// CloseTLSHandshake 保留. 表示连接由于无法完成 TLS 握手而关闭 (例如无法验证服务器证书).
	CloseTLSHandshake StatusCode = 1015
)

func (StatusCode) Bytes

func (c StatusCode) Bytes() []byte

func (StatusCode) Error

func (c StatusCode) Error() string

func (StatusCode) Uint16

func (c StatusCode) Uint16() uint16

Jump to

Keyboard shortcuts

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