docker: Index | Files

package units

import ""

Package units provides helper function to parse and print size and time units in human-readable format.


Package Files

duration.go size.go ulimit.go


const (
    KB  = 1000
    MB  = 1000 * KB
    GB  = 1000 * MB
    TB  = 1000 * GB
    PB  = 1000 * TB

    KiB = 1024
    MiB = 1024 * KiB
    GiB = 1024 * MiB
    TiB = 1024 * GiB
    PiB = 1024 * TiB


func BytesSize Uses

func BytesSize(size float64) string

BytesSize returns a human-readable size in bytes, kibibytes, mebibytes, gibibytes, or tebibytes (eg. "44kiB", "17MiB").

func CustomSize Uses

func CustomSize(format string, size float64, base float64, _map []string) string

CustomSize returns a human-readable approximation of a size using custom format.

func FromHumanSize Uses

func FromHumanSize(size string) (int64, error)

FromHumanSize returns an integer from a human-readable specification of a size using SI standard (eg. "44kB", "17MB").

func HumanDuration Uses

func HumanDuration(d time.Duration) string

HumanDuration returns a human-readable approximation of a duration (eg. "About a minute", "4 hours ago", etc.).

func HumanSize Uses

func HumanSize(size float64) string

HumanSize returns a human-readable approximation of a size capped at 4 valid numbers (eg. "2.746 MB", "796 KB").

func HumanSizeWithPrecision Uses

func HumanSizeWithPrecision(size float64, precision int) string

HumanSizeWithPrecision allows the size to be in any precision, instead of 4 digit precision used in units.HumanSize.

func RAMInBytes Uses

func RAMInBytes(size string) (int64, error)

RAMInBytes parses a human-readable string representing an amount of RAM in bytes, kibibytes, mebibytes, gibibytes, or tebibytes and returns the number of bytes, or -1 if the string is unparseable. Units are case-insensitive, and the 'b' suffix is optional.

type Rlimit Uses

type Rlimit struct {
    Type int    `json:"type,omitempty"`
    Hard uint64 `json:"hard,omitempty"`
    Soft uint64 `json:"soft,omitempty"`

Rlimit specifies the resource limits, such as max open files.

type Ulimit Uses

type Ulimit struct {
    Name string
    Hard int64
    Soft int64

Ulimit is a human friendly version of Rlimit.

func ParseUlimit Uses

func ParseUlimit(val string) (*Ulimit, error)

ParseUlimit parses and returns a Ulimit from the specified string.

func (*Ulimit) GetRlimit Uses

func (u *Ulimit) GetRlimit() (*Rlimit, error)

GetRlimit returns the RLimit corresponding to Ulimit.

func (*Ulimit) String Uses

func (u *Ulimit) String() string

Package units imports 5 packages (graph). Updated 2019-05-16. Refresh now. Tools for package owners.