utils

package
v0.3.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSize = 16 * 0x400

Variables

This section is empty.

Functions

func Copy

func Copy(dst io.Writer, src io.Reader) (err error)

func GetBuffer

func GetBuffer() *bytes.Buffer

func GetBytes

func GetBytes(size int) []byte

func GetScheme

func GetScheme(ur string) (scheme, etc string, err error)

func PutBuffer

func PutBuffer(b *bytes.Buffer)

func PutBytes

func PutBytes(b []byte)

func Relay

func Relay(local, remote io.ReadWriter)

Relay pipe

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache use map save history

func NewCache

func NewCache[K comparable, V any]() *Cache[K, V]

NewCache create new cache

func (*Cache[K, V]) Add

func (c *Cache[K, V]) Add(domain K, mark V)

Add .

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(domain K) (V, bool)

Get .

type LRU

type LRU[K comparable, V any] struct {
	// contains filtered or unexported fields
}

LRU Least Recently Used

func NewLru

func NewLru[K comparable, V any](capacity uint, timeout time.Duration) *LRU[K, V]

NewLru create new lru cache

func (*LRU[K, V]) Add

func (l *LRU[K, V]) Add(key K, value V, opts ...Option)

func (*LRU[K, V]) Delete

func (l *LRU[K, V]) Delete(key K)

Delete delete a key from cache

func (*LRU[K, V]) Load

func (l *LRU[K, V]) Load(key K) (v V, ok bool)

func (*LRU[K, V]) ReverseLoad

func (l *LRU[K, V]) ReverseLoad(v V) (k K, ok bool)

func (*LRU[K, V]) ValueExist

func (l *LRU[K, V]) ValueExist(key V) bool

type Option

type Option func(*options)

func WithExpireTime

func WithExpireTime(t time.Time) Option

type Pool

type Pool interface {
	GetBytes(size int) []byte
	PutBytes(b []byte)

	GetBuffer() *bytes.Buffer
	PutBuffer(b *bytes.Buffer)
}
var DefaultPool Pool = &pool{}

type Unit

type Unit int

Unit .

const (
	//B .
	B Unit = 0
	//KB .
	KB Unit = 1
	//MB .
	MB Unit = 2
	//GB .
	GB Unit = 3
	//TB .
	TB Unit = 4
	//PB .
	PB Unit = 5
)

func ReducedUnit

func ReducedUnit(byte float64) (result float64, unit Unit)

ReducedUnit .

func (Unit) String

func (u Unit) String() string

Jump to

Keyboard shortcuts

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