util

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

various utilities

Index

Constants

This section is empty.

Variables

View Source
var Discard discard
View Source
var StringCompare = strings.Compare
View Source
var Zero = new(zeroReader)

reader that reads zeros

Functions

func CheckFile

func CheckFile(fpath string) (exists bool)

CheckFile returns true if a file exists

func ClientNameFromID

func ClientNameFromID(id []byte) (name string)

func EnsureDir

func EnsureDir(fpath string) (err error)

ensure a directory is made returns error if it can't be made

func EnsureFile

func EnsureFile(fpath string, size uint64) (err error)

ensure a file and its parent directory exists

func FormatRate

func FormatRate(rate float64) (str string)

FormatRate formats a floating point b/s as string with closest unit

func RandBoolPercent

func RandBoolPercent(percent uint8) bool

func RandStr

func RandStr(l int) string

func Ratio

func Ratio(tx, rx float64) (r float64)

func SchemePath added in v0.4.5

func SchemePath(u *url.URL) (scheme string, path string)

func StartedAt

func StartedAt() time.Time

func WriteFull

func WriteFull(w io.Writer, d []byte) (err error)

ensure a byteslices is written in full

Types

type Buffer

type Buffer struct {
	bytes.Buffer
}

func (*Buffer) Close

func (b *Buffer) Close() error

Close implements io.Closer

type Rate

type Rate struct {
	Samples []RateSample
	// contains filtered or unexported fields
}

func NewRate

func NewRate(sampleLen int) *Rate

func (*Rate) AddSample

func (r *Rate) AddSample(n uint64)

func (*Rate) BDecode

func (r *Rate) BDecode(rd io.Reader) (err error)

func (*Rate) BEncode

func (r *Rate) BEncode(w io.Writer) (err error)

func (*Rate) Current

func (r *Rate) Current() (cur uint64)

func (*Rate) Max

func (r *Rate) Max() (max uint64)

func (*Rate) Mean

func (r *Rate) Mean() float64

func (*Rate) Min

func (r *Rate) Min() (min uint64)

func (*Rate) PrevTickTime

func (r *Rate) PrevTickTime() time.Time

func (*Rate) Tick

func (r *Rate) Tick()

type RateSample

type RateSample [2]uint64

(magnitude, time)

func (*RateSample) Add

func (s *RateSample) Add(n uint64)

func (*RateSample) Clear

func (s *RateSample) Clear()

func (*RateSample) Set

func (s *RateSample) Set(n uint64)

func (RateSample) Time

func (s RateSample) Time() time.Time

func (RateSample) Value

func (s RateSample) Value() uint64

Jump to

Keyboard shortcuts

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