Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalUvarint(buf []byte) (uint64, int)
- func ContextTick(ctx context.Context, d time.Duration) <-chan time.Time
- func Debugf(prefix, format string, v ...any)
- func Div128(hi, lo, y uint64) (hiQuo, loQuo uint64)
- func Error(v ...any)
- func Errorf(prefix, format string, v ...any)
- func Fatalf(format string, v ...any)
- func GetOutboundIPv6() ([]netip.Addr, error)
- func IsLogLevelDebug() bool
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func Logf(prefix, format string, v ...any)
- func MarshalJSON(val any) ([]byte, error)
- func MarshalJSONIndent(val any, indent string) ([]byte, error)
- func NetIPGetEUI48Information(addr netip.Addr)
- func NetIPIsCGNAT(addr netip.Addr) bool
- func NewJSONDecoder(reader io.Reader) *gojson.Decoder
- func NewJSONEncoder(writer io.Writer) *gojson.Encoder
- func Noticef(prefix, format string, v ...any)
- func NthElementSlice[S ~[]E, E cmp.Ordered](s S, k int)
- func NthElementSliceFunc[S ~[]E, E any](s S, cmp func(a, b E) int, k int)
- func Panic(v ...any)
- func Panicf(format string, v ...any)
- func ParseUint64(s []byte) (uint64, error)
- func PreviousPowerOfTwo(x uint64) int
- func Print(v ...any)
- func ReadCanonicalUvarint(r io.ByteReader) (uint64, error)
- func ReadFullProgressive[T ~[]byte](r io.Reader, dst *T, size int) (n int, err error)
- func SiUnits(number float64, decimals int) string
- func SliceCount[S ~[]E, E any](s S, f func(E) bool) (count int)
- func SplitWork(routines int, workSize uint64, ...) error
- func UVarInt64Size[T uint64 | int | uint8](v T) (n int)
- func UVarInt64SliceSize[T uint64 | int](v []T) (n int)
- func UnmarshalJSON(data []byte, val any) error
- func XMRUnits(v uint64) string
- func XorShift64Star(x uint64) uint64
- type Cache
- type CircularBuffer
- func (b *CircularBuffer[T]) Current() T
- func (b *CircularBuffer[T]) Exists(value T) bool
- func (b *CircularBuffer[T]) Get(index uint32) T
- func (b *CircularBuffer[T]) Push(value T)
- func (b *CircularBuffer[T]) PushUnique(value T) bool
- func (b *CircularBuffer[T]) Replace(value, replace T)
- func (b *CircularBuffer[T]) Reverse()
- func (b *CircularBuffer[T]) Slice() []T
- type ExtendedIPFlags
- type ExtendedIPNet
- type LRUCache
- type LimitedByteReader
- type LogLevel
- type MapCache
- type NilCache
- type ReaderAndByteReader
Constants ¶
const ( LogLevelError = LogLevel(1 << iota) LogLevelInfo LogLevelNotice LogLevelDebug )
const ( IFA_F_SECONDARY = 0x01 IFA_F_TEMPORARY = IFA_F_SECONDARY IFA_F_NODAD = 0x02 IFA_F_OPTIMISTIC = 0x04 IFA_F_DADFAILED = 0x08 IFA_F_HOMEADDRESS = 0x10 IFA_F_DEPRECATED = 0x20 IFA_F_TENTATIVE = 0x40 IFA_F_PERMANENT = 0x80 IFA_F_MANAGETEMPADDR = 0x100 IFA_F_NOPREFIXROUTE = 0x200 IFA_F_MCAUTOJOIN = 0x400 )
const IFA_FLAGS = 0x8
Variables ¶
var ErrNonCanonicalEncoding = errors.New("binary: varint has non canonical encoding")
var GOMAXPROCS = min(runtime.GOMAXPROCS(0), runtime.NumCPU())
var GlobalLogLevel = LogLevelError | LogLevelInfo
var JsonEncodeOptions = []gojson.EncodeOptionFunc{gojson.DisableHTMLEscape(), gojson.DisableNormalizeUTF8()}
var LogFile bool
var LogFunc bool
Functions ¶
func CanonicalUvarint ¶ added in v4.1.0
CanonicalUvarint decodes a uint64 from buf and returns that value and the number of bytes read (> 0). If an error occurred, the value is 0 and the number of bytes n is <= 0 meaning:
- n == 0: buf too small;
- n < 0: value larger than 64 bits (overflow) and -n is the number of bytes read.
The function errors if non-canonical bytes were read.
func GetOutboundIPv6 ¶
func IsLogLevelDebug ¶ added in v4.1.0
func IsLogLevelDebug() bool
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
func MarshalJSON ¶
func NetIPIsCGNAT ¶
func NthElementSlice ¶
NthElementSlice QuickSelect implementation k is the desired index value, where array[k] is the k+1 smallest element values between s[0, k-1] are guaranteed <= to s[k] values between s[k+1, len(s)] are guaranteed >= to s[k]
func NthElementSliceFunc ¶
NthElementSliceFunc QuickSelect implementation k is the desired index value, where array[k] is the k+1 smallest element values between s[0, k-1] are guaranteed <= to s[k] values between s[k+1, len(s)] are guaranteed >= to s[k]
func ParseUint64 ¶
ParseUint64 parses uint64 from s.
It is equivalent to strconv.ParseUint(s, 10, 64), but is faster.
func PreviousPowerOfTwo ¶
func ReadCanonicalUvarint ¶ added in v4.1.0
func ReadCanonicalUvarint(r io.ByteReader) (uint64, error)
ReadCanonicalUvarint reads an encoded unsigned integer from r and returns it as a uint64. The error is ErrNonCanonicalEncoding if non-canonical bytes were read. The error is io.EOF only if no bytes were read. If an io.EOF happens after reading some but not all the bytes, ReadCanonicalUvarint returns io.ErrUnexpectedEOF.
func ReadFullProgressive ¶ added in v4.7.0
ReadFullProgressive Reads into buf up to size bytes by doubling size each time
func SliceCount ¶
func UVarInt64SliceSize ¶
func UnmarshalJSON ¶
func XorShift64Star ¶
XorShift64Star Implementation of xorshift* https://en.wikipedia.org/wiki/Xorshift#xorshift* x must be initialized to a non-zero value
Types ¶
type Cache ¶
type Cache[K comparable, T any] interface { Get(key K) (value T, ok bool) Set(key K, value T) Delete(key K) Clear() Stats() (hits, misses uint64) }
type CircularBuffer ¶
type CircularBuffer[T comparable] struct { // contains filtered or unexported fields }
func NewCircularBuffer ¶
func NewCircularBuffer[T comparable](size int) *CircularBuffer[T]
func (*CircularBuffer[T]) Current ¶
func (b *CircularBuffer[T]) Current() T
func (*CircularBuffer[T]) Exists ¶
func (b *CircularBuffer[T]) Exists(value T) bool
func (*CircularBuffer[T]) Get ¶
func (b *CircularBuffer[T]) Get(index uint32) T
func (*CircularBuffer[T]) Push ¶
func (b *CircularBuffer[T]) Push(value T)
func (*CircularBuffer[T]) PushUnique ¶
func (b *CircularBuffer[T]) PushUnique(value T) bool
func (*CircularBuffer[T]) Replace ¶
func (b *CircularBuffer[T]) Replace(value, replace T)
func (*CircularBuffer[T]) Reverse ¶
func (b *CircularBuffer[T]) Reverse()
func (*CircularBuffer[T]) Slice ¶
func (b *CircularBuffer[T]) Slice() []T
type ExtendedIPFlags ¶
type ExtendedIPFlags uint
const ( FlagTemporary ExtendedIPFlags = 1 << iota FlagPermanent FlagNoPrefixRoute FlagManageTempAddress FlagStablePrivacy FlagDeprecated )
type ExtendedIPNet ¶
type ExtendedIPNet struct {
IP net.IP // network number
Mask net.IPMask // network mask
Flags ExtendedIPFlags
}
func InterfaceAddrs ¶
func InterfaceAddrs(ifi *net.Interface) ([]*ExtendedIPNet, error)
InterfaceAddrs returns a list of unicast interface addresses for a specific interface.
func (*ExtendedIPNet) String ¶
func (n *ExtendedIPNet) String() string
type LRUCache ¶
type LRUCache[K comparable, T any] struct { // contains filtered or unexported fields }
func NewLRUCache ¶
func NewLRUCache[K comparable, T any](size int) *LRUCache[K, T]
type LimitedByteReader ¶
type LimitedByteReader struct {
R ReaderAndByteReader // underlying reader
N int64 // max bytes remaining
}
A LimitedByteReader reads from R but limits the amount of data returned to just N bytes. Each call to Read updates N to reflect the new amount remaining. Read returns EOF when N <= 0 or when the underlying R returns EOF.
func LimitByteReader ¶
func LimitByteReader(r ReaderAndByteReader, n int64) *LimitedByteReader
LimitByteReader returns a Reader that reads from r but stops with EOF after n bytes. The underlying implementation is a *LimitedReader.
func (*LimitedByteReader) Left ¶
func (l *LimitedByteReader) Left() int64
func (*LimitedByteReader) ReadByte ¶
func (l *LimitedByteReader) ReadByte() (v byte, err error)
type MapCache ¶
type MapCache[K comparable, T any] struct { // contains filtered or unexported fields }
func NewMapCache ¶
func NewMapCache[K comparable, T any](preAllocateSize int) *MapCache[K, T]
type NilCache ¶ added in v4.1.0
type NilCache[K comparable, T any] struct { }
func NewNilCache ¶ added in v4.1.0
func NewNilCache[K comparable, T any]() NilCache[K, T]
type ReaderAndByteReader ¶
type ReaderAndByteReader interface {
io.Reader
io.ByteReader
}