humanizeutil

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(val uint64) redact.SafeString

Count formats a unitless integer value like a row count. It uses separating commas for large values (e.g. "1,000,000").

func DataRate

func DataRate(bytes int64, elapsed time.Duration) redact.SafeString

DataRate formats the passed byte count over duration as "x MiB/s".

func Duration

func Duration(val time.Duration) redact.SafeString

Duration formats a duration in a user-friendly way. The result is not exact and the granularity is no smaller than microseconds.

Examples:

0              ->  "0µs"
123456ns       ->  "123µs"
12345678ns     ->  "12ms"
12345678912ns  ->  "1.2s"

func IBytes

func IBytes(value int64) redact.SafeString

IBytes is an int64 version of go-humanize's IBytes.

func LongDuration

func LongDuration(val time.Duration) redact.SafeString

LongDuration formats a duration that is expected to be on the order of minutes / hours / days in a user-friendly way. The result is not exact and the granularity is no smaller than seconds.

Examples:

  • 0 seconds
  • 1 second
  • 3 minutes
  • 1 hour
  • 5 days
  • 1000 days

func ParseBytes

func ParseBytes(s string) (int64, error)

ParseBytes is an int64 version of go-humanize's ParseBytes.

Types

type BytesValue

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

BytesValue is a struct that implements flag.Value and pflag.Value suitable to create command-line parameters that accept sizes specified using a format recognized by humanize. The value is written atomically, so that it is safe to use this struct to make a parameter configurable that is used by an asynchronous process spawned before command-line argument handling. This is useful e.g. for the log file settings which are used by the asynchronous log file GC daemon.

func NewBytesValue

func NewBytesValue(val *int64) *BytesValue

NewBytesValue creates a new pflag.Value bound to the specified int64 variable. It also happens to be a flag.Value.

func (*BytesValue) IsSet

func (b *BytesValue) IsSet() bool

IsSet returns true iff Set has successfully been called.

func (*BytesValue) SafeFormat

func (b *BytesValue) SafeFormat(w redact.SafePrinter, _ rune)

SafeFormat implements the redact.SafeFormatter interface.

func (*BytesValue) Set

func (b *BytesValue) Set(s string) error

Set implements the flag.Value and pflag.Value interfaces.

func (*BytesValue) String

func (b *BytesValue) String() string

String implements the flag.Value and pflag.Value interfaces.

func (*BytesValue) Type

func (b *BytesValue) Type() string

Type implements the pflag.Value interface.

Jump to

Keyboard shortcuts

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