utils

package
v0.3.1-beta.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 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 struct {
	// contains filtered or unexported fields
}

Cache use map save history

func NewCache

func NewCache() *Cache

NewCache create new cache

func (*Cache) Add

func (c *Cache) Add(domain string, mark any)

Add .

func (*Cache) Get

func (c *Cache) Get(domain string) (any, 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 int, 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]) ValueExist

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

func (*LRU[K, V]) ValueLoad

func (l *LRU[K, V]) ValueLoad(v V) (k K, ok 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