util

package
v0.0.0-...-da267cc Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package util provides general utility functions shared by the other modules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstSpeed

func EstSpeed(startTime int64, lastTime int64, bytesSent uint64) uint64

EstSpeed will estimate a peers speed using downloaded amount over time

func Exists

func Exists(path string) bool

Exists checks for the existence of a file path

func FindFile

func FindFile(p string) string

FindFile will walk up the directory tree until it find a file. Max depth of 4

func GenRandomBytes

func GenRandomBytes(size int) (blk []byte, err error)

GenRandomBytes returns N bytes of random data

func HumanBytesString

func HumanBytesString(s uint64) string

HumanBytesString produces a human readable representation of an SI size.

Bytes(82854982) -> 83MB noinspection GoUnusedExportedFunction

func HumanIBytesString

func HumanIBytesString(s uint64) string

HumanIBytesString produces a human readable representation of an IEC size.

IBytes(82854982) -> 79MiB noinspection GoUnusedExportedFunction

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

IsPrivateIP returns true if the IP provided is a valid routable address

func Min

func Min(a, b int) int

Min is math.Min for int

func MinInt

func MinInt(a, b int) int

MinInt returns the smallest of two int values

func NewPasskey

func NewPasskey() string

NewPasskey generated a string suitable for use as a passkey

func Now

func Now() time.Time

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration works exactly like time.ParseDuration except that it supports durations longer than hours Formats: s, m, h, d, w, M, y

func StringToBool

func StringToBool(s string, def bool) bool

StringToBool converts a string to a bool returning a default value on failure

func StringToFloat64

func StringToFloat64(s string, def float64) float64

StringToFloat64 converts a string to a float64 returning a default value on failure

func StringToInt16

func StringToInt16(s string, def int16) int16

StringToInt16 converts a string to a int16 returning a default value on failure noinspection GoUnusedExportedFunction

func StringToInt32

func StringToInt32(s string, def int32) int32

StringToInt32 converts a string to a uint32 returning a default value on failure

func StringToTime

func StringToTime(s string) time.Time

StringToTime converts a string to a time.Time returning a default value on failure

func StringToUInt

func StringToUInt(s string, def int) int

StringToUInt converts a string to a uint32 returning a default value on failure

func StringToUInt16

func StringToUInt16(s string, def uint16) uint16

StringToUInt16 converts a string to a uint16 returning a default value on failure

func StringToUInt32

func StringToUInt32(s string, def uint32) uint32

StringToUInt32 converts a string to a uint32 returning a default value on failure

func StringToUInt64

func StringToUInt64(s string, def uint64) uint64

StringToUInt64 converts a string to a uint32 returning a default value on failure

func TimeToString

func TimeToString(t time.Time) string

TimeToString converts a time.Time to a common RFC1123Z string

func UMax

func UMax(a, b uint) uint

UMax is math.Max for uint

func UMax16

func UMax16(a, b uint16) uint16

UMax16 is math.Max for uint16

func UMax32

func UMax32(a, b uint32) uint32

UMax32 is math.Max for uint64

func UMax64

func UMax64(a, b uint64) uint64

UMax64 is math.Max for uint64

func UMin64

func UMin64(a, b uint64) uint64

UMin64 is math.Min for uint64

func WaitForSignal

func WaitForSignal(ctx context.Context, f func(ctx context.Context) error)

WaitForSignal will execute a function when a matching os.Signal is received This is mostly designed to shutdown & cleanup services

Types

This section is empty.

Jump to

Keyboard shortcuts

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