util

package
v0.0.0-...-92b04c0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AMF0_NUMBER = iota // 浮点数
	AMF0_BOOLEAN
	AMF0_STRING
	AMF0_OBJECT
	AMF0_MOVIECLIP
	AMF0_NULL
	AMF0_UNDEFINED
	AMF0_REFERENCE
	AMF0_ECMA_ARRAY
	AMF0_END_OBJECT
	AMF0_STRICT_ARRAY
	AMF0_DATE
	AMF0_LONG_STRING
	AMF0_UNSUPPORTED
	AMF0_RECORDSET
	AMF0_XML_DOCUMENT
	AMF0_TYPED_OBJECT
	AMF0_AVMPLUS_OBJECT
)
View Source
const (
	AMF3_UNDEFINED = iota
	AMF3_NULL
	AMF3_FALSE
	AMF3_TRUE
	AMF3_INTEGER
	AMF3_DOUBLE
	AMF3_STRING
	AMF3_XML_DOC
	AMF3_DATE
	AMF3_ARRAY
	AMF3_OBJECT
	AMF3_XML
	AMF3_BYTE_ARRAY
	AMF3_VECTOR_INT
	AMF3_VECTOR_UINT
	AMF3_VECTOR_DOUBLE
	AMF3_VECTOR_OBJECT
	AMF3_DICTIONARY
)
View Source
const (
	APIErrorNone   = 0
	APIErrorDecode = iota + 4000
	APIErrorQueryParse
	APIErrorNoBody
)
View Source
const (
	APIErrorNotFound = iota + 4040
	APIErrorNoStream
	APIErrorNoConfig
	APIErrorNoPusher
	APIErrorNoSubscriber
	APIErrorNoSEI
)
View Source
const (
	APIErrorInternal = iota + 5000
	APIErrorJSONEncode
	APIErrorPublish
	APIErrorSave
	APIErrorOpen
)

Variables

View Source
var (
	END_OBJ   = []byte{0, 0, AMF0_END_OBJECT}
	ObjectEnd = &struct{}{}
	Undefined = &struct{}{}
)
View Source
var BigEndian bigEndian

BigEndian is the big-endian implementation of ByteOrder.

View Source
var Crc32_Table = []uint32{}/* 256 elements not displayed */
View Source
var (
	FieldNoExist error = errors.New("field no exist")
)
View Source
var LittleEndian littleEndian
View Source
var Null = struct{}{}
View Source
var PoolSize = 16
View Source
var RTPReorderBufferLen uint16 = 50

Functions

func BasicAuth

func BasicAuth(u, p string, next http.Handler) http.Handler

func BigLittleSwap

func BigLittleSwap(v uint) uint

func Bit1

func Bit1(b byte, index int) bool

Bit1 检查字节中的某一位是否为1 |0|1|2|3|4|5|6|7|

func ByteToUint32

func ByteToUint32(data []byte, bigEndian bool) (ret uint32, err error)

千万注意大小端,RTMP是大端

func ByteToUint32N

func ByteToUint32N(data []byte) (ret uint32, err error)

// 千万注意大小端,RTMP是大端

func ByteToUint64N

func ByteToUint64N(data []byte) (ret uint64, err error)

// 千万注意大小端,RTMP是大端

func CORS

func CORS(next http.Handler) http.Handler

CORS 加入跨域策略头包含CORP

func Clone

func Clone[T any](x T) *T

func ConcatBuffers

func ConcatBuffers[T ~[]byte](input []T) (out []byte)

ConcatBuffers 合并碎片内存为一个完整内存

func Conditoinal

func Conditoinal[T any](cond bool, t, f T) T

func Conf2Listener

func Conf2Listener(conf string) (protocol string, ports []uint16)

func ConvertNum

func ConvertNum[F Integer, T Integer](from F, to T) T

func CreateShutdownScript

func CreateShutdownScript() error

func CurrentDir

func CurrentDir(path ...string) string

func Exist

func Exist(filename string) bool

检查文件或目录是否存在 如果由 filename 指定的文件或目录存在则返回 true,否则返回 false

func FetchValue

func FetchValue[T any](t T) func() T

func GetBE

func GetBE[T Integer](b []byte, num *T) T

func GetFillBytes

func GetFillBytes(data byte, n int) []byte

func GetPCR

func GetPCR(v uint64) uint64

func GetPtsDts

func GetPtsDts(v uint64) uint64

func GetUev

func GetUev(buff []byte, start int) (value int, pos int)

哥伦布解码

func IsLANAddr

func IsLANAddr(ip string) (bool, string)

IsLANAddr 检测 IP 地址字符串是否是内网地址

func IsLANIp

func IsLANIp(ip net.IP) (bool, string)

IsLANIp 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func IsSubdir

func IsSubdir(baseDir, joinedDir string) bool

判断目录是否是基础目录的子目录

func LastElement

func LastElement[T any](s []T) T

func ListenUDP

func ListenUDP(address string, networkBuffer int) (*net.UDPConn, error)

func MapList

func MapList[K comparable, V any, R any](m *Map[K, V], f func(K, V) R) (r []R)

func MarshalAMFs

func MarshalAMFs(v ...any) []byte

func PutBE

func PutBE[T Integer](b []byte, num T) []byte

func PutPCR

func PutPCR(pcr uint64) uint64

func PutPtsDts

func PutPtsDts(v uint64) uint64

func ReadAMF

func ReadAMF[T string | float64 | bool | map[string]any](amf *AMF) (result T)

func ReadBE

func ReadBE[T Integer](b []byte) (num T)

func ReadByteToUint16

func ReadByteToUint16(r io.Reader, bigEndian bool) (data uint16, err error)

func ReadByteToUint24

func ReadByteToUint24(r io.Reader, bigEndian bool) (data uint32, err error)

func ReadByteToUint32

func ReadByteToUint32(r io.Reader, bigEndian bool) (data uint32, err error)

func ReadByteToUint40

func ReadByteToUint40(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint48

func ReadByteToUint48(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint64

func ReadByteToUint64(r io.Reader, bigEndian bool) (data uint64, err error)

func ReadByteToUint8

func ReadByteToUint8(r io.Reader) (data uint8, err error)

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) error

func RetryStopErr

func RetryStopErr(err error) retryStop

func ReturnError

func ReturnError(code int, msg string, rw http.ResponseWriter, r *http.Request)

func ReturnFetchList

func ReturnFetchList[T any](fetch func() []T, rw http.ResponseWriter, r *http.Request)

func ReturnFetchValue

func ReturnFetchValue[T any](fetch func() T, rw http.ResponseWriter, r *http.Request)

func ReturnOK

func ReturnOK(rw http.ResponseWriter, r *http.Request)

func ReturnValue

func ReturnValue(v any, rw http.ResponseWriter, r *http.Request)

func SizeOfBuffers

func SizeOfBuffers[T ~[]byte](buf []T) (size int)

SizeOfBuffers 计算Buffers的内容长度

func SplitBuffers

func SplitBuffers[T ~[]byte](buf []T, size int) (result [][]T)

SplitBuffers 按照一定大小分割 Buffers

func ToFloat64

func ToFloat64(num interface{}) float64

func Uint32ToByte

func Uint32ToByte(data uint32, bigEndian bool) (ret []byte, err error)

func WaitTerm

func WaitTerm(cancel context.CancelFunc)

func WriteUint16ToByte

func WriteUint16ToByte(w io.Writer, data uint16, bigEndian bool) error

func WriteUint24ToByte

func WriteUint24ToByte(w io.Writer, data uint32, bigEndian bool) error

func WriteUint32ToByte

func WriteUint32ToByte(w io.Writer, data uint32, bigEndian bool) error

func WriteUint40ToByte

func WriteUint40ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint48ToByte

func WriteUint48ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint64ToByte

func WriteUint64ToByte(w io.Writer, data uint64, bigEndian bool) error

func WriteUint8ToByte

func WriteUint8ToByte(w io.Writer, data uint8) error

Types

type AMF

type AMF struct {
	Buffer
}

func (*AMF) Marshal

func (amf *AMF) Marshal(v any) []byte

func (*AMF) Marshals

func (amf *AMF) Marshals(v ...any) []byte

func (*AMF) ReadBool

func (amf *AMF) ReadBool() (result bool)

func (*AMF) ReadNumber

func (amf *AMF) ReadNumber() (result float64)

func (*AMF) ReadObject

func (amf *AMF) ReadObject() (result map[string]any)

func (*AMF) ReadShortString

func (amf *AMF) ReadShortString() (result string)

func (*AMF) Unmarshal

func (amf *AMF) Unmarshal() (obj any, err error)

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"msg"`
}

type APIResult

type APIResult struct {
	Code    int    `json:"code"`
	Data    any    `json:"data"`
	Message string `json:"msg"`
}

type BLL

type BLL struct {
	List[Buffer]
	ByteLength int
}

ByteLinkList

func (*BLL) Clear

func (list *BLL) Clear()

func (*BLL) GetByte

func (list *BLL) GetByte(index int) (b byte)

func (*BLL) GetUint24

func (list *BLL) GetUint24(index int) uint32

func (*BLL) GetUintN

func (list *BLL) GetUintN(index int, n int) (result uint32)

func (*BLL) NewReader

func (list *BLL) NewReader() *BLLReader

func (*BLL) Push

func (list *BLL) Push(item *ListItem[Buffer])

func (*BLL) Recycle

func (list *BLL) Recycle()

全部回收掉

func (*BLL) Shift

func (list *BLL) Shift() (item *ListItem[Buffer])

func (*BLL) ToBuffers

func (list *BLL) ToBuffers() (result net.Buffers)

func (*BLL) ToBytes

func (list *BLL) ToBytes() (b []byte)

func (*BLL) WriteTo

func (list *BLL) WriteTo(w io.Writer) (int64, error)

type BLLReader

type BLLReader struct {
	*ListItem[Buffer]
	// contains filtered or unexported fields
}

func (*BLLReader) CanRead

func (r *BLLReader) CanRead() bool

func (*BLLReader) GetOffset

func (r *BLLReader) GetOffset() int

func (*BLLReader) LEB128Unmarshal

func (r *BLLReader) LEB128Unmarshal() (uint, int, error)

func (*BLLReader) ReadBE

func (r *BLLReader) ReadBE(n int) (be uint32, err error)

func (*BLLReader) ReadByte

func (r *BLLReader) ReadByte() (b byte, err error)

func (*BLLReader) ReadN

func (r *BLLReader) ReadN(n int) (result net.Buffers)

func (*BLLReader) Skip

func (r *BLLReader) Skip(n int) (err error)

func (*BLLReader) WriteNTo

func (r *BLLReader) WriteNTo(n int, result *net.Buffers) (actual int)

type BLLs

type BLLs struct {
	List[*BLL]
	ByteLength int
}

func (*BLLs) NewReader

func (list *BLLs) NewReader() *BLLsReader

func (*BLLs) Push

func (list *BLLs) Push(item *ListItem[Buffer])

func (*BLLs) PushValue

func (list *BLLs) PushValue(item *BLL)

func (*BLLs) Recycle

func (list *BLLs) Recycle()

func (*BLLs) ToBuffers

func (list *BLLs) ToBuffers() (result net.Buffers)

func (*BLLs) ToBytes

func (list *BLLs) ToBytes() (result []byte)

func (*BLLs) ToList

func (list *BLLs) ToList() (result [][][]byte)

type BLLsReader

type BLLsReader struct {
	*ListItem[*BLL]
	BLLReader
}

func (*BLLsReader) CanRead

func (r *BLLsReader) CanRead() bool

func (*BLLsReader) ReadByte

func (r *BLLsReader) ReadByte() (b byte, err error)

type Buffer

type Buffer []byte

Buffer 用于方便自动扩容的内存写入,已经读取

func (Buffer) Bytes

func (b Buffer) Bytes() []byte

func (Buffer) CanRead

func (b Buffer) CanRead() bool

func (Buffer) CanReadN

func (b Buffer) CanReadN(n int) bool

func (Buffer) Cap

func (b Buffer) Cap() int

func (Buffer) Clone

func (b Buffer) Clone() (result Buffer)

func (Buffer) Len

func (b Buffer) Len() int

func (*Buffer) Malloc

func (b *Buffer) Malloc(count int) Buffer

Malloc 扩大原来的buffer的长度,返回新增的buffer

func (*Buffer) MarshalAMFs

func (b *Buffer) MarshalAMFs(v ...any)

func (*Buffer) Read

func (b *Buffer) Read(buf []byte) (n int, err error)

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() byte

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

func (*Buffer) ReadN

func (b *Buffer) ReadN(n int) Buffer

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() uint16

func (*Buffer) ReadUint24

func (b *Buffer) ReadUint24() uint32

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() uint32

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() uint64

func (*Buffer) Relloc

func (b *Buffer) Relloc(count int)

Relloc 改变 buffer 到指定大小

func (*Buffer) Reset

func (b *Buffer) Reset()

func (Buffer) Reuse

func (Buffer) Reuse() bool

func (*Buffer) Split

func (b *Buffer) Split(n int) (result net.Buffers)

func (Buffer) SubBuf

func (b Buffer) SubBuf(start int, length int) Buffer

func (*Buffer) Write

func (b *Buffer) Write(a []byte) (n int, err error)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(v byte)

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(v float64)

func (*Buffer) WriteString

func (b *Buffer) WriteString(a string)

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(v uint16)

func (*Buffer) WriteUint24

func (b *Buffer) WriteUint24(v uint32)

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(v uint32)

type Builder

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

构造器

func NewBuilder

func NewBuilder() *Builder

func (*Builder) AddBool

func (b *Builder) AddBool(name string) *Builder

func (*Builder) AddField

func (b *Builder) AddField(field string, typ reflect.Type) *Builder

添加字段

func (*Builder) AddFloat64

func (b *Builder) AddFloat64(name string) *Builder

func (*Builder) AddInt64

func (b *Builder) AddInt64(name string) *Builder

func (*Builder) AddString

func (b *Builder) AddString(name string) *Builder

func (*Builder) Build

func (b *Builder) Build() *Struct

根据预先添加的字段构建出结构体

type BytesPool

type BytesPool []List[Buffer]

func (BytesPool) Get

func (p BytesPool) Get(size int) (item *ListItem[Buffer])

func (BytesPool) GetShell

func (p BytesPool) GetShell(b []byte) (item *ListItem[Buffer])

获取来自真实内存的切片的——假内存块,即只回收外壳

type Crc32Reader

type Crc32Reader struct {
	R     io.Reader
	Crc32 uint32
}

func (*Crc32Reader) Read

func (cr *Crc32Reader) Read(b []byte) (n int, err error)

func (*Crc32Reader) ReadCrc32UIntAndCheck

func (cr *Crc32Reader) ReadCrc32UIntAndCheck() (err error)

type Crc32Writer

type Crc32Writer struct {
	W     io.Writer
	Crc32 uint32
}

func (*Crc32Writer) Write

func (wr *Crc32Writer) Write(b []byte) (n int, err error)

type EcmaArray

type EcmaArray map[string]any

type IBytes

type IBytes interface {
	Len() int
	Bytes() []byte
	Reuse() bool
}

IBytes 用于区分传入的内存是否是复用内存,例如从网络中读取的数据,如果是复用内存,需要尽早复制

type IList

type IList[T any] interface {
	Push(*ListItem[T])
	Shift() *ListItem[T]
	Clear()
}

type IOVec

type IOVec struct {
	Data   [][]byte
	Length int
	// contains filtered or unexported fields
}

func (*IOVec) Append

func (iov *IOVec) Append(b []byte)

func (*IOVec) WriteTo

func (iov *IOVec) WriteTo(w io.Writer, n int) (written int, err error)

type IOVecWriter

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

func NewIOVecWriter

func NewIOVecWriter(w io.Writer) (iow *IOVecWriter)

func (*IOVecWriter) Flush

func (iow *IOVecWriter) Flush() error

func (*IOVecWriter) Write

func (iow *IOVecWriter) Write(data []byte) (written int, err error)

type Instance

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

结构体的值

func (*Instance) Addr

func (i *Instance) Addr() interface{}

func (Instance) Field

func (in Instance) Field(name string) (reflect.Value, error)

func (*Instance) Interface

func (i *Instance) Interface() interface{}

func (*Instance) SetBool

func (in *Instance) SetBool(name string, value bool)

func (*Instance) SetFloat64

func (in *Instance) SetFloat64(name string, value float64)

func (*Instance) SetInt64

func (in *Instance) SetInt64(name string, value int64)

func (*Instance) SetString

func (in *Instance) SetString(name, value string)

type Integer

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

type LimitBuffer

type LimitBuffer struct {
	Buffer
}

LimitBuffer 限制buffer的长度,不会改变原来的buffer,防止内存泄漏

func (LimitBuffer) Clone

func (b LimitBuffer) Clone() (result LimitBuffer)

func (*LimitBuffer) Malloc

func (b *LimitBuffer) Malloc(count int) (result LimitBuffer)

func (*LimitBuffer) ReadN

func (b *LimitBuffer) ReadN(n int) (result LimitBuffer)

func (LimitBuffer) SubBuf

func (b LimitBuffer) SubBuf(start int, length int) (result LimitBuffer)

func (*LimitBuffer) Write

func (b *LimitBuffer) Write(a []byte) (n int, err error)

type List

type List[T any] struct {
	ListItem[T]
	Length int
}

func (*List[T]) Clear

func (p *List[T]) Clear()

func (*List[T]) PoolShift

func (p *List[T]) PoolShift() (head *ListItem[T])

func (*List[T]) Push

func (p *List[T]) Push(item *ListItem[T])

func (*List[T]) PushValue

func (p *List[T]) PushValue(value T)

func (*List[T]) Range

func (p *List[T]) Range(do func(value T) bool)

func (*List[T]) RangeItem

func (p *List[T]) RangeItem(do func(*ListItem[T]) bool)

func (*List[T]) Recycle

func (p *List[T]) Recycle()

func (*List[T]) Shift

func (p *List[T]) Shift() (head *ListItem[T])

func (*List[T]) ShiftValue

func (p *List[T]) ShiftValue() T

func (*List[T]) Transfer

func (p *List[T]) Transfer(target IList[T])

Transfer 把链表中的所有元素转移到另一个链表中

func (*List[T]) Unshift

func (p *List[T]) Unshift(item *ListItem[T])

func (*List[T]) UnshiftValue

func (p *List[T]) UnshiftValue(value T)

type ListItem

type ListItem[T any] struct {
	Value     T
	Next, Pre *ListItem[T] `json:"-" yaml:"-"`
	Pool      *List[T]     `json:"-" yaml:"-"` // 回收池
	// contains filtered or unexported fields
}

func NewListItem

func NewListItem[T any](value T) *ListItem[T]

func (*ListItem[T]) InsertAfter

func (item *ListItem[T]) InsertAfter(insert *ListItem[T])

func (*ListItem[T]) InsertAfterValue

func (item *ListItem[T]) InsertAfterValue(value T) (result *ListItem[T])

func (*ListItem[T]) InsertBefore

func (item *ListItem[T]) InsertBefore(insert *ListItem[T])

func (*ListItem[T]) InsertBeforeValue

func (item *ListItem[T]) InsertBeforeValue(value T) (result *ListItem[T])

func (*ListItem[T]) IsRoot

func (item *ListItem[T]) IsRoot() bool

func (*ListItem[T]) Range

func (item *ListItem[T]) Range(do func(value T) bool)

func (*ListItem[T]) RangeItem

func (item *ListItem[T]) RangeItem(do func(*ListItem[T]) bool)

func (*ListItem[T]) Recycle

func (item *ListItem[T]) Recycle()

type Map

type Map[K comparable, V any] struct {
	sync.Map
}

func (*Map[K, V]) Add

func (m *Map[K, V]) Add(k K, v V) bool

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(k K) (v V, ok bool)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (result V)

func (*Map[K, V]) Has

func (m *Map[K, V]) Has(k K) (ok bool)

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() (l int)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(K, V))

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V)

func (*Map[K, V]) ToList

func (m *Map[K, V]) ToList() (r []V)

type Pool

type Pool[T any] List[T]

func (*Pool[T]) Get

func (p *Pool[T]) Get() (item *ListItem[T])

type Promise

type Promise[S any] struct {
	context.Context
	context.CancelCauseFunc
	context.CancelFunc
	Value S
}

func NewPromise

func NewPromise[S any](value S) *Promise[S]

func (*Promise[S]) Await

func (p *Promise[S]) Await() (err error)

func (*Promise[S]) Reject

func (r *Promise[S]) Reject(err error)

func (*Promise[S]) Resolve

func (r *Promise[S]) Resolve()

type RTPReorder

type RTPReorder[T comparable] struct {
	Total uint32 // 总共收到的包数量
	Drop  uint32 // 丢弃的包数量
	// contains filtered or unexported fields
}

RTPReorder RTP包乱序重排

func (*RTPReorder[T]) Pop

func (p *RTPReorder[T]) Pop() (result T)

Pop 从缓存中取出一个包,需要连续调用直到返回nil

func (*RTPReorder[T]) Push

func (p *RTPReorder[T]) Push(seq uint16, v T) (result T)

type Recyclable

type Recyclable interface {
	Recycle()
}

type ReuseBuffer

type ReuseBuffer struct {
	Buffer
}

ReuseBuffer 重用buffer,内容可能会被覆盖,要尽早复制

func (ReuseBuffer) Reuse

func (ReuseBuffer) Reuse() bool

type Ring

type Ring[T any] struct {
	Value T // for use by client; untouched by this library
	// contains filtered or unexported fields
}

A Ring is an element of a circular list, or ring. Rings do not have a beginning or end; a pointer to any ring element serves as reference to the entire ring. Empty rings are represented as nil Ring pointers. The zero value for a Ring is a one-element ring with a nil Value.

func NewRing

func NewRing[T any](n int) *Ring[T]

New creates a ring of n elements.

func (*Ring[T]) Do

func (r *Ring[T]) Do(f func(T))

Do calls function f on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r.

func (*Ring[T]) Len

func (r *Ring[T]) Len() int

Len computes the number of elements in ring r. It executes in time proportional to the number of elements.

func (r *Ring[T]) Link(s *Ring[T]) *Ring[T]

Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty.

If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to that subring (if no elements were removed, the result is still the original value for r.Next(), and not nil).

If r and s point to different rings, linking them creates a single ring with the elements of s inserted after r. The result points to the element following the last element of s after insertion.

func (*Ring[T]) Move

func (r *Ring[T]) Move(n int) *Ring[T]

Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.

func (*Ring[T]) Next

func (r *Ring[T]) Next() *Ring[T]

Next returns the next ring element. r must not be empty.

func (*Ring[T]) Prev

func (r *Ring[T]) Prev() *Ring[T]

Prev returns the previous ring element. r must not be empty.

func (r *Ring[T]) Unlink(n int) *Ring[T]

Unlink removes n % r.Len() elements from the ring r, starting at r.Next(). If n % r.Len() == 0, r remains unchanged. The result is the removed subring. r must not be empty.

type SSE

type SSE struct {
	http.ResponseWriter
	context.Context
}

func NewSSE

func NewSSE(w http.ResponseWriter, ctx context.Context) *SSE

func (*SSE) Write

func (sse *SSE) Write(data []byte) (n int, err error)

func (*SSE) WriteEvent

func (sse *SSE) WriteEvent(event string, data []byte) (err error)

func (*SSE) WriteExec

func (sse *SSE) WriteExec(cmd *exec.Cmd) error

func (*SSE) WriteJSON

func (sse *SSE) WriteJSON(data any) error

func (*SSE) WriteYAML

func (sse *SSE) WriteYAML(data any) error

type SafeChan

type SafeChan[T any] struct {
	C chan T
	// contains filtered or unexported fields
}

SafeChan安全的channel,可以防止close后被写入的问题

func (*SafeChan[T]) Close

func (sc *SafeChan[T]) Close() bool

Close senders为0的时候可以安全关闭,否则不能关闭

func (*SafeChan[T]) Init

func (sc *SafeChan[T]) Init(n int)

func (*SafeChan[T]) IsClosed

func (sc *SafeChan[T]) IsClosed() bool

func (*SafeChan[T]) IsEmpty

func (sc *SafeChan[T]) IsEmpty() bool

func (*SafeChan[T]) IsFull

func (sc *SafeChan[T]) IsFull() bool

func (*SafeChan[T]) Send

func (sc *SafeChan[T]) Send(v T) bool

type Slice

type Slice[T comparable] []T

func (*Slice[T]) Add

func (s *Slice[T]) Add(v T)

func (*Slice[T]) Delete

func (s *Slice[T]) Delete(v T) bool

func (Slice[T]) Len

func (s Slice[T]) Len() int

func (*Slice[T]) Reset

func (s *Slice[T]) Reset()

func (*Slice[T]) ResetAppend

func (s *Slice[T]) ResetAppend(first T)

type Struct

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

实际生成的结构体,基类 结构体的类型

func (Struct) New

func (s Struct) New() *Instance

type SysIOVec

type SysIOVec struct {
	Base   uintptr
	Length uint64
}

Directories

Path Synopsis
pio

Jump to

Keyboard shortcuts

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