amoy

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 40 Imported by: 14

README

amoy

Just another collection of Go utilities among yet another packages.

Telling a programmer there's already a library to do X is like telling a songwriter there's already a song about love.

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

IEC Sizes. kibis of bits

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

View Source
const (
	// MinUint the smallest possible value of uint.
	MinUint = uint(0)
	// MaxUint the largest possible value of uint.
	MaxUint = ^uint(0)

	// MinUint32 the smallest possible value of uint32.
	MinUint32 = uint32(0)
	// MaxUint32 the largest possible value of uint32.
	MaxUint32 = ^uint32(0)

	// MinUint64 the smallest possible value of uint64.
	MinUint64 = uint64(0)
	// MaxUint64 the largest possible value of uint64.
	MaxUint64 = ^uint64(0)

	// MinInt the smallest possible value of int.
	MinInt = -MaxInt - 1
	// MaxInt the largest possible value of int.
	MaxInt = int(^uint(0) >> 1)

	// MinInt32 the smallest possible value of int.
	MinInt32 = -MaxInt32 - 1
	// MaxInt32 the largest possible value of int.
	MaxInt32 = int32(^uint32(0) >> 1)

	// MinInt64 the smallest possible value of int.
	MinInt64 = -MaxInt64 - 1
	// MaxInt64 the largest possible value of int.
	MaxInt64 = int64(^uint64(0) >> 1)
)
View Source
const (
	ZeroDuration time.Duration = 0
	Nanosecond   time.Duration = 1
	Microsecond                = 1000 * Nanosecond
	Millisecond                = 1000 * Microsecond
	Second                     = 1000 * Millisecond
	Minute                     = 60 * Second
	Hour                       = 60 * Minute
	Day                        = 24 * Hour
	Week                       = 7 * Day
	Year                       = 365 * Day
)

Common durations. Inherited from libexec/src/time/time.go

Variables

View Source
var (

	// Simple style functions
	StyleIndex     = makeFlexFgStyle("238", "250")
	StyleMessage   = makeFgStyle("200")
	StyleName      = makeFgStyle("207")
	StyleDate      = makeFgStyle("82")
	StyleHighlight = makeFgStyle("227")
	StyleLabel     = makeFgStyle("51")
	StyleAmount    = makeFgStyle("207")
	StyleDot       = colorFg("•", "236")
	StyleDash      = colorFg("-", "236")
)
View Source
var DiscardWriteCloser io.WriteCloser = discardCloser{}

DiscardWriteCloser is an WriteCloser on which all Write calls succeed without doing anything.

View Source
var DiscardWriter io.Writer = io.Discard

DiscardWriter is an Writer on which all Write calls succeed without doing anything.

View Source
var EmptyStr string

EmptyStr is the missing empty string for Go :)

View Source
var (
	// QuitRead indicates the arbitrary error means to quit from reading.
	QuitRead = errors.New("quit read by line")
)

Functions

func AfterNow

func AfterNow(t time.Time) bool

AfterNow indicates if the given time is after current time.

func AppendLines

func AppendLines(path string, lines []string) error

AppendLines appends the given lines to a text file.

func Atoi

func Atoi(s string) (int, error)

Atoi is equivalent to strconv.Atoi(s).

func Atoi32

func Atoi32(s string) (int32, error)

Atoi32 is equivalent to strconv.ParseInt(s, 10, 32).

func Atoi64

func Atoi64(s string) (int64, error)

Atoi64 is equivalent to strconv.ParseInt(s, 10, 64).

func Atou

func Atou(s string) (uint, error)

Atou is equivalent to strconv.ParseUint(s, 10, 0).

func Atou32

func Atou32(s string) (uint32, error)

Atou32 is equivalent to strconv.ParseUint(s, 10, 32).

func Atou64

func Atou64(s string) (uint64, error)

Atou64 is equivalent to strconv.ParseUint(s, 10, 64).

func BackOffRetry

func BackOffRetry(work func() error, times uint, delay time.Duration) error

BackOffRetry retries to execute given function with exponential backoff delay.

func BackOffRetryIf

func BackOffRetryIf(work func() error, retryIf RetryIfFunc, times uint, delay time.Duration) error

BackOffRetryIf retries to execute given function with exponential backoff delay if condition meets.

func BeforeNow

func BeforeNow(t time.Time) bool

BeforeNow indicates if the given time is before current time.

func ChangeDir

func ChangeDir(path string)

ChangeDir changes the current working directory.

func ComputeSI

func ComputeSI(input float64) (float64, string)

ComputeSI finds the most appropriate SI prefix for the given number and returns the prefix along with the value adjusted to be within that prefix.

See also: SI, ParseSI.

e.g. ComputeSI(2.2345e-12) -> (2.2345, "p")

func CountLines

func CountLines(path string) (count int, err error)

CountLines counts all lines from the given file

func CurrentFunctionName

func CurrentFunctionName() string

CurrentFunctionName returns name of current function.

func DateNowStr added in v0.0.15

func DateNowStr() string

DateNowStr returns the date of current local time. e.g. 2021-09-01

func DateUTCNowStr added in v0.0.15

func DateUTCNowStr() string

DateUTCNowStr returns the date of current UTC time. e.g. 2021-09-01

func DayBegin added in v0.0.15

func DayBegin(t time.Time, loc *time.Location) time.Time

DayBegin returns the first moment of the given time in given location.

func DayEnd added in v0.0.15

func DayEnd(t time.Time, loc *time.Location) time.Time

DayEnd returns the last moment of the given time in given location.

func Days added in v0.0.14

func Days(n float64) time.Duration

Days returns a duration of given days.

func DecodeBase36ToBytes

func DecodeBase36ToBytes(b string) []byte

DecodeBase36ToBytes decodes a base36 string to a byte slice, using alphabet.

func DistinctInts added in v0.0.15

func DistinctInts(ori []int) []int

DistinctInts returns a new slice with the same order but without duplicate int elements.

func EncodeBytesAsBase36

func EncodeBytesAsBase36(b []byte) string

EncodeBytesAsBase36 encodes a byte slice to base36 string.

func EncodeBytesAsBase36Bytes

func EncodeBytesAsBase36Bytes(b []byte) []byte

EncodeBytesAsBase36Bytes encodes a byte slice to base36.

func FeelLucky

func FeelLucky(rate float64) bool

FeelLucky returns the random decision as per a given successful rate.

func FixedRetry

func FixedRetry(work func() error, times uint, delay time.Duration) error

FixedRetry retries to execute given function with consistent same delay.

func FixedRetryIf

func FixedRetryIf(work func() error, retryIf RetryIfFunc, times uint, delay time.Duration) error

FixedRetryIf retries to execute given function with consistent same delay if condition meets.

func FractionCeil

func FractionCeil(a, b int) int

FractionCeil returns the least integer value greater than or equal to a/b.

func FractionFloor

func FractionFloor(a, b int) int

FractionFloor returns the greatest integer value less than or equal to a/b.

func FractionFractional added in v0.0.15

func FractionFractional(a, b int) float64

FractionFractional returns the fractional part of floating-point number represented by a/b.

func FractionRound

func FractionRound(a, b int) int

FractionRound returns the nearest integer, rounding half away from zero of a/b.

func FractionTrunc

func FractionTrunc(a, b int) int

FractionTrunc returns the integer value of a/b.

func Ftoa

func Ftoa(num float64) string

Ftoa converts a float to a string with no trailing zeros.

func FtoaWithDigits

func FtoaWithDigits(num float64, digits int) string

FtoaWithDigits converts a float to a string but limits the resulting string to the given number of decimal places, and no trailing zeros.

func FunctionName

func FunctionName(f interface{}) string

FunctionName returns name of the given function.

func GetEnvVar

func GetEnvVar(key, fallback string) string

GetEnvVar returns the value of the given environment variable or the fallback.

func GetFingerprint

func GetFingerprint(s string) string

GetFingerprint returns SHA1 hash of a string in fingerprint format.

func GetSID

func GetSID() string

GetSID returns a new random UUID in base36 string.

func GetUUID

func GetUUID() string

GetUUID returns a new random UUID in hex string.

func GetUnixTime

func GetUnixTime() int64

GetUnixTime returns a current time in unix timestamp.

func Hours added in v0.0.14

func Hours(n float64) time.Duration

Hours returns a duration of given hours.

func HumanizeBytes

func HumanizeBytes(s uint64) string

HumanizeBytes produces a human readable representation of an SI size.

HumanizeBytes(82854982) -> 83 MB

func HumanizeDuration

func HumanizeDuration(duration time.Duration) string

HumanizeDuration humanizes time.Duration output to a meaningful value.

func HumanizeIBytes

func HumanizeIBytes(s uint64) string

HumanizeIBytes produces a human readable representation of an IEC size.

HumanizeIBytes(82854982) -> 79 MiB

func IsTextFile

func IsTextFile(path string) bool

IsTextFile loads and checks if the given path is a text file.

func Itoa

func Itoa(i int) string

Itoa is equivalent to strconv.Itoa(i).

func Itoa32

func Itoa32(i int32) string

Itoa32 is equivalent to strconv.FormatInt(int64(i), 10).

func Itoa64

func Itoa64(i int64) string

Itoa64 is equivalent to strconv.FormatInt(i, 10).

func LoadJSONFile

func LoadJSONFile(s interface{}, fileName string) error

LoadJSONFile loads object from the given JSON file.

func LocalDayBegin added in v0.0.15

func LocalDayBegin(t time.Time) time.Time

LocalDayBegin returns the first moment of the given time in local timezone.

func LocalDayEnd added in v0.0.15

func LocalDayEnd(t time.Time) time.Time

LocalDayEnd returns the last moment of the given time in local timezone.

func MergeMaps

func MergeMaps(ms ...map[string]string) map[string]string

MergeMaps returns a new map as union set of given maps.

func Milliseconds added in v0.0.14

func Milliseconds(n float64) time.Duration

Milliseconds returns a duration of given milliseconds.

func Minutes added in v0.0.14

func Minutes(n float64) time.Duration

Minutes returns a duration of given minutes.

func NewLocalDate added in v0.0.15

func NewLocalDate(year int, month time.Month, day int) time.Time

NewLocalDate returns the first moment of the given date in local timezone.

func NewUTCDate added in v0.0.15

func NewUTCDate(year int, month time.Month, day int) time.Time

NewUTCDate returns the first moment of the given date in UTC timezone.

func NoopZapLogger

func NoopZapLogger() *zap.Logger

NoopZapLogger returns a zap logger enabled at fatal level, it basically logs nothing.

func NowStr added in v0.0.14

func NowStr() string

NowStr returns the current local time in RFC3339Nano format. e.g. 2021-09-01T12:52:33.250864+08:00

func ParseHumanizedBytes

func ParseHumanizedBytes(s string) (uint64, error)

ParseHumanizedBytes parses a string representation of bytes into the number of bytes it represents.

ParseHumanizedBytes("42 MB") -> 42000000, nil ParseHumanizedBytes("42 mib") -> 44040192, nil

func ParseIntSequence added in v0.0.15

func ParseIntSequence(s, splitSep, rangeSep string) ([]int, error)

ParseIntSequence parses sequences like "9-12,10,20" into slices of int like [9, 10, 11, 12, 20].

func ParseSI

func ParseSI(input string) (float64, string, error)

ParseSI parses an SI string back into the number and unit.

See also: SI, ComputeSI.

e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil)

func ParseUnixTime

func ParseUnixTime(u int64) time.Time

ParseUnixTime converts a unix timestamp to local time.

func PostJSONAndDumps

func PostJSONAndDumps(url string, dataReq, dataResp interface{}, timeout time.Duration, headers map[string]string, dumpReqPath, dumpRespPath string) error

PostJSONAndDumps sends payload in JSON to target URL with given timeout and headers and dumps response and parses response as JSON.

func PostJSONWithHeaders

func PostJSONWithHeaders(url string, dataReq, dataResp interface{}, timeout time.Duration, headers map[string]string) error

PostJSONWithHeaders sends payload in JSON to target URL with given timeout and headers and parses response as JSON.

func PrintColorfulJSON

func PrintColorfulJSON(data interface{})

PrintColorfulJSON outputs commit in JSON with indent and syntax highlight to console.

func PrintJSON

func PrintJSON(data interface{})

PrintJSON outputs commit in JSON with indent to console.

func PrintOneLineJSON

func PrintOneLineJSON(data interface{})

PrintOneLineJSON outputs commit in JSON in one line.

func Quote

func Quote() string

Quote returns the quote of current version.

func ReadByLine

func ReadByLine(path string, callback LineFunc) (err error)

ReadByLine iterates the given file by lines (the line ending chars are not included).

func ReadLines

func ReadLines(path string) (lines []string, err error)

ReadLines reads all lines from the given file (the line ending chars are not included).

func RegexMatch added in v0.0.15

func RegexMatch(pat, s string) (bool, error)

RegexMatch reports whether the string s contains any match of the regular expression pattern.

func RenderTableString

func RenderTableString(header []string, rows [][]string) string

RenderTableString renders the rows as table and returns as string for console.

func ReverseStr

func ReverseStr(s string) string

ReverseStr returns a reversed string of the given string.

func RoundToFixed added in v0.0.14

func RoundToFixed(num float64, precision int) float64

RoundToFixed returns the rounding floating number with given precision.

func RunCombinedCommand

func RunCombinedCommand(command string) ([]byte, error)

RunCombinedCommand runs the command and returns its combined standard output and standard error.

func RunQuietCommand

func RunQuietCommand(command string) error

RunQuietCommand runs the command quietly and returns no standard output nor standard error.

func RunSimpleCommand

func RunSimpleCommand(command string) ([]byte, []byte, error)

RunSimpleCommand simply runs the command and returns its standard output and standard error.

func SI

func SI(input float64, unit string) string

SI returns a string with default formatting.

SI uses Ftoa to format float value, removing trailing zeros.

See also: ComputeSI, ParseSI.

e.g. SI(1000000, "B") -> 1 MB e.g. SI(2.2345e-12, "F") -> 2.2345 pF

func SIWithDigits

func SIWithDigits(input float64, decimals int, unit string) string

SIWithDigits works like SI but limits the resulting string to the given number of decimal places.

e.g. SIWithDigits(1000000, 0, "B") -> 1 MB e.g. SIWithDigits(2.2345e-12, 2, "F") -> 2.23 pF

func SaveJSONFile

func SaveJSONFile(data interface{}, fileName string) error

SaveJSONFile saves object as a JSON file.

func Seconds added in v0.0.14

func Seconds(n float64) time.Duration

Seconds returns a duration of given seconds.

func ShortFunctionName

func ShortFunctionName(f interface{}) string

ShortFunctionName returns short name of the given function.

func ShortNowStr added in v0.0.14

func ShortNowStr() string

ShortNowStr returns the current local time in short format. e.g. 2021-09-01 12:52:33

func ShortUTCNowStr added in v0.0.15

func ShortUTCNowStr() string

ShortUTCNowStr returns the current UTC time in short format. e.g. 2021-09-01 04:52:33

func SimpleRetry

func SimpleRetry(work func() error) error

SimpleRetry retries to execute given function for 3 times and with exponential backoff delay starting at 300ms.

func SimpleZapLogger

func SimpleZapLogger() *zap.Logger

SimpleZapLogger returns a zap logger with color console as output.

func SimpleZapSugaredLogger

func SimpleZapSugaredLogger() *zap.SugaredLogger

SimpleZapSugaredLogger returns a sugared zap logger with color console as output.

func SleepForDays added in v0.0.14

func SleepForDays(n float64)

SleepForDays pauses the current goroutine for at least the n days.

func SleepForHours added in v0.0.14

func SleepForHours(n float64)

SleepForHours pauses the current goroutine for at least the n hours.

func SleepForMilliseconds added in v0.0.14

func SleepForMilliseconds(n float64)

SleepForMilliseconds pauses the current goroutine for at least the n milliseconds.

func SleepForMinutes added in v0.0.14

func SleepForMinutes(n float64)

SleepForMinutes pauses the current goroutine for at least the n minutes.

func SleepForSeconds added in v0.0.14

func SleepForSeconds(n float64)

SleepForSeconds pauses the current goroutine for at least the n seconds.

func StyleBold

func StyleBold(val string) string

StyleBold renders a string in bold.

func StyleCrossOut

func StyleCrossOut(val string) string

StyleCrossOut renders a string with cross-out.

func StyleEmail

func StyleEmail(email string) string

StyleEmail renders a string of email with terminal colors.

func SubstrAfterFirst

func SubstrAfterFirst(s, sub string) string

SubstrAfterFirst returns a substring which starts after the first occurrence of target and continues to the end, or empty string if the target is not found or empty.

func SubstrAfterLast

func SubstrAfterLast(s, sub string) string

SubstrAfterLast returns a substring which starts after the last occurrence of target and continues to the end, or empty string if the target is not found or empty.

func SubstrBeforeFirst

func SubstrBeforeFirst(s, sub string) string

SubstrBeforeFirst returns a substring which starts starts at the begin of a string and continues to the first occurrence of target, or empty string if the target is not found or empty.

func SubstrBeforeLast

func SubstrBeforeLast(s, sub string) string

SubstrBeforeLast returns a substring which starts starts at the begin of a string and continues to the last occurrence of target, or empty string if the target is not found or empty.

func SubstrOrOrigin

func SubstrOrOrigin(subFunc func(string, string) string, s, sub string) string

SubstrOrOrigin returns the original string if the target is missed in substr function.

func ToJSON

func ToJSON(data interface{}) string

ToJSON converts data into one-line JSON.

func TrimUTF8BOM

func TrimUTF8BOM(b []byte) []byte

TrimUTF8BOM removes the leading UTF-8 byte order mark from bytes.

func TruncateStr

func TruncateStr(s string, limit int) string

TruncateStr renders a truncated string of the given length, or original one if it's shorter.

func UTCDayBegin added in v0.0.15

func UTCDayBegin(t time.Time) time.Time

UTCDayBegin returns the first moment of the given time in UTC timezone.

func UTCDayEnd added in v0.0.15

func UTCDayEnd(t time.Time) time.Time

UTCDayEnd returns the last moment of the given time in UTC timezone.

func UTCNow added in v0.0.14

func UTCNow() time.Time

UTCNow returns the current UTC time.

func UTCNowStr added in v0.0.14

func UTCNowStr() string

UTCNowStr returns the current UTC time in RFC3339Nano format. e.g. 2021-09-01T04:52:33.251188Z

func UnzipDir

func UnzipDir(srcZip string, destDir string) ([]string, error)

UnzipDir decompresses a zip archive, extracts all files and folders within the zip file to an output directory.

func UnzipFile

func UnzipFile(srcZip string, handle func(file *zip.File) error) error

UnzipFile decompresses a zip archive, extracts all files and call handlers.

func Utoa

func Utoa(i uint) string

Utoa is equivalent to strconv.FormatUint(uint64(i), 10).

func Utoa32

func Utoa32(i uint32) string

Utoa32 is equivalent to strconv.FormatUint(uint64(i), 10).

func Utoa64

func Utoa64(i uint64) string

Utoa64 is equivalent to strconv.FormatUint(i, 10).

func Weeks added in v0.0.14

func Weeks(n float64) time.Duration

Weeks returns a duration of given weeks.

func WriteContent added in v0.0.15

func WriteContent(path string, content string) error

WriteContent writes the given content into a file.

func WriteLines

func WriteLines(path string, lines []string) error

WriteLines writes the given lines as a text file.

func Years added in v0.0.14

func Years(n float64) time.Duration

Years returns a duration of given years.

func ZipContent

func ZipContent(destZip string, content ArchiveContent) error

ZipContent compresses data entries into a single zip archive file.

func ZipDir

func ZipDir(destZip string, srcDirs ...string) error

ZipDir compresses one or many directories into a single zip archive file.

func ZipFile

func ZipFile(destZip string, srcFiles ...string) error

ZipFile compresses one or many files into a single zip archive file.

Types

type ArchiveContent

type ArchiveContent map[string][]byte

ArchiveContent represents a map between filename and data.

func UnzipContent

func UnzipContent(srcZip string) (ArchiveContent, error)

UnzipContent decompresses a zip archive, extracts all files within the zip file to map of bytes.

type Command

type Command struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Command represents an external command being running or exited.

func StartCommand

func StartCommand(command string, opts ...*CommandOptions) (*Command, error)

StartCommand starts the specified command with given options but does not wait for it to complete.

func StartSimpleCommand

func StartSimpleCommand(command string, writerStdout, writerStderr io.Writer) (*Command, error)

StartSimpleCommand starts the specified command but does not wait for it to complete, and simultaneously writes its standard output and standard error to given writers.

func (*Command) Done

func (c *Command) Done() <-chan struct{}

Done returns a channel that's closed when the command exits.

func (*Command) Error

func (c *Command) Error() error

Error returns the error after the command exits if it exists.

func (*Command) Exited

func (c *Command) Exited() bool

Exited reports whether the command has exited.

func (*Command) Kill

func (c *Command) Kill() error

Kill causes the command to exit immediately, and does not wait until it has actually exited.

func (*Command) ProcessID

func (c *Command) ProcessID() int

ProcessID indicates PID of the command.

func (*Command) StartedAt

func (c *Command) StartedAt() time.Time

StartedAt indicates the moment that the command started.

func (*Command) Stderr

func (c *Command) Stderr() []byte

Stderr returns a slice holding the unread portion of the standard error of the command.

func (*Command) Stdout

func (c *Command) Stdout() []byte

Stdout returns a slice holding the unread portion of the standard output of the command.

func (*Command) StoppedAt

func (c *Command) StoppedAt() time.Time

StoppedAt indicates the moment that the command stopped or zero if it's still running.

type CommandOptions

type CommandOptions struct {
	WorkDir        string
	Stdout, Stderr io.Writer
	// TODO: not implemented
	Stdin   io.Reader
	Timeout time.Time
	EnvVar  map[string]string
}

CommandOptions represents custom options to execute external command.

type LineFunc

type LineFunc func(line string) (err error)

LineFunc stands for a handler for each line string.

type LogConfig

type LogConfig struct {
	ConsoleFormat string
	FileFormat    string
	MaxFileSizeMB int
	MaxBackups    int
	CompressFile  bool
}

LogConfig stands for config of logging.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a wrapper of uber/zap logger with dynamic log level.

func NewJSONLogger

func NewJSONLogger(fileName string, debug bool) *Logger

NewJSONLogger returns a Logger with given log path and debug mode and all output format is JSON.

func NewLogger

func NewLogger(fileName string, debug bool, cfgs ...LogConfig) *Logger

NewLogger returns a Logger with given log path and debug mode.

func NewPersistentLogger

func NewPersistentLogger(fileName string, debug bool) *Logger

NewPersistentLogger returns a Logger with given log path and debug mode and all output format is JSON, and never cleans up.

func (*Logger) GetLogLevel

func (l *Logger) GetLogLevel() zapcore.Level

GetLogLevel returns the log level of loggers inside the wrapper.

func (*Logger) Logger

func (l *Logger) Logger() *zap.Logger

Logger returns a zap logger inside the wrapper.

func (*Logger) LoggerSugared

func (l *Logger) LoggerSugared() *zap.SugaredLogger

LoggerSugared returns a sugared zap logger inside the wrapper.

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(level string)

SetLogLevel sets the log level of loggers inside the wrapper.

type NamedValues

type NamedValues map[string]string

NamedValues represents a named value map for named capturing groups.

func ExtractNamedValues

func ExtractNamedValues(r *regexp.Regexp, str string) NamedValues

ExtractNamedValues returns a named value map with the given compiled regular expression and original string.

func (NamedValues) IsEmpty

func (l NamedValues) IsEmpty() bool

IsEmpty indicates if the given map is empty.

type RetryIfFunc

type RetryIfFunc func(error) bool

RetryIfFunc represents function signature of retry if function.

type Stopwatch

type Stopwatch struct {
	// contains filtered or unexported fields
}

Stopwatch represents a instance for timer with start time.

func NewStopwatch

func NewStopwatch() *Stopwatch

NewStopwatch returns a stopwatch just started.

func (*Stopwatch) Elapsed

func (sw *Stopwatch) Elapsed() time.Duration

Elapsed returns the elapsed time since the timer started.

func (*Stopwatch) Show

func (sw *Stopwatch) Show()

Show outputs the elapsed time in console with terminal colors.

Jump to

Keyboard shortcuts

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