golib

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 18 Imported by: 3

README

golib

This is just some common functionality I use across several projects. No guarantees that anything will work. You probably shouldn't use the repo directly, just copy anything you want from it.

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 BToMb

func BToMb(b uint64) uint64

func CreateGUID

func CreateGUID() string

func EstSpeed added in v1.1.0

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

EstSpeed will estimate a peers speed using downloaded amount over time

func Exists added in v1.0.1

func Exists(path string) bool

func FindFile added in v1.0.2

func FindFile(p string, minRootDir string) string

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

func GenRandomBytes added in v1.1.0

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

GenRandomBytes returns N bytes of random data

func GetFileSize added in v1.0.1

func GetFileSize(fileName string) (int64, error)

func HumanBytesString added in v1.1.0

func HumanBytesString(s uint64) string

HumanBytesString produces a human readable representation of an SI size.

Bytes(82854982) -> 83MB noinspection GoUnusedExportedFunction

func HumanIBytesString added in v1.1.0

func HumanIBytesString(s uint64) string

HumanIBytesString produces a human readable representation of an IEC size.

IBytes(82854982) -> 79MiB noinspection GoUnusedExportedFunction

func IsDir added in v1.0.2

func IsDir(path string) bool

func MinInt added in v1.1.0

func MinInt(a, b int) int

MinInt returns the smallest of two int values

func RandomString

func RandomString(n int) string

func RenderMD

func RenderMD(md string) string

func StringToBool added in v1.1.0

func StringToBool(s string, def bool) bool

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

func StringToFloat64 added in v1.1.0

func StringToFloat64(s string, def float64) float64

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

func StringToInt16 added in v1.1.0

func StringToInt16(s string, def int16) int16

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

func StringToTime added in v1.1.0

func StringToTime(s string) time.Time

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

func StringToUInt added in v1.1.0

func StringToUInt(s string, def int) int

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

func StringToUInt16 added in v1.1.0

func StringToUInt16(s string, def uint16) uint16

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

func StringToUInt32 added in v1.1.0

func StringToUInt32(s string, def uint32) uint32

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

func StringToUInt64 added in v1.1.0

func StringToUInt64(s string, def uint64) uint64

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

func TimeToString added in v1.1.0

func TimeToString(t time.Time) string

TimeToString converts a time.Time to a common RFC1123Z string

func ToTable

func ToTable(rows [][]string, opts TableOpts) string

func UMax added in v1.1.0

func UMax(a, b uint) uint

UMax is math.Max for uint

func UMax16 added in v1.1.0

func UMax16(a, b uint16) uint16

UMax16 is math.Max for uint16

func UMax32 added in v1.1.0

func UMax32(a, b uint32) uint32

UMax32 is math.Max for uint64

func UMax64 added in v1.1.0

func UMax64(a, b uint64) uint64

UMax64 is math.Max for uint64

func UMin64 added in v1.1.0

func UMin64(a, b uint64) uint64

UMin64 is math.Min for uint64

func WaitForSignal added in v1.0.1

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

type SysStats

type SysStats struct {
	Alloc      uint64
	TotalAlloc uint64
	Sys        uint64
	NumGC      uint32
	GoRoutines int
}

func GetStats

func GetStats() SysStats

type TableOpts

type TableOpts struct {
	Title         string
	Headers       []string
	Padding       int
	DrawRowBorder bool
}

func DefaultTableOpts

func DefaultTableOpts() TableOpts

Jump to

Keyboard shortcuts

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