ht

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 7 Imported by: 0

README

ht - Human-readable types

Go Reference

This package provides parsing and printing utilities for:

  • Durations with an additional d unit;
  • Byte sizes;
  • Clocks;
  • Time rates.

Documentation

Overview

Package ht provides parsing and printing utilities for human-readable types.

Index

Constants

View Source
const (
	KB ByteSizeSI = 1000
	MB            = KB * 1000
	GB            = MB * 1000
	TB            = GB * 1000
	PB            = TB * 1000
	EB            = PB * 1000
)
View Source
const (
	KiB ByteSizeIEC = 1024
	MiB             = KiB * 1024
	GiB             = MiB * 1024
	TiB             = GiB * 1024
	PiB             = TiB * 1024
	EiB             = PiB * 1024
)
View Source
const (
	Nanosecond  = Duration(time.Nanosecond)
	Microsecond = Duration(time.Microsecond)
	Millisecond = Duration(time.Millisecond)
	Second      = Duration(time.Second)
	Minute      = Duration(time.Minute)
	Hour        = Duration(time.Hour)
	Day         = Duration(24 * time.Hour)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSizeIEC

type ByteSizeIEC uint64

ByteSizeIEC is a byte size in IEC units.

func ParseByteSizeIEC

func ParseByteSizeIEC(s string) (ByteSizeIEC, error)

ParseByteSizeIEC parses a byte size string. A byte size string is a decimal number with an optional fraction and unit suffix, such as "1k", "1.5M" or "2MB".

Valid IEC units are: - k, K, KiB - kibibyte - M, MiB - mebibyte - G, GiB - gibibyte - T, TiB - tebibyte - P, PiB - pebibyte - E, EiB - exbibyte

Valid SI units are: - kB, KB - kilobyte - MB - megabyte - GB - gigabyte - TB - terabyte - PB - petabyte - EB - exabyte

NOTE: Accepts both IEC and SI units.

func (ByteSizeIEC) MarshalJSON

func (b ByteSizeIEC) MarshalJSON() ([]byte, error)

func (ByteSizeIEC) MarshalText

func (b ByteSizeIEC) MarshalText() ([]byte, error)

func (ByteSizeIEC) String

func (b ByteSizeIEC) String() string

func (*ByteSizeIEC) UnmarshalJSON

func (b *ByteSizeIEC) UnmarshalJSON(data []byte) error

func (*ByteSizeIEC) UnmarshalText

func (b *ByteSizeIEC) UnmarshalText(data []byte) error

type ByteSizeSI

type ByteSizeSI uint64

ByteSizeSI is a byte size in SI units.

func ParseByteSizeSI

func ParseByteSizeSI(s string) (ByteSizeSI, error)

ParseByteSizeSI parses a byte size string. A byte size string is a decimal number with an optional fraction and unit suffix, such as "1k", "1.5M" or "2MB".

Valid IEC units are: - k, K, KiB - kibibyte - M, MiB - mebibyte - G, GiB - gibibyte - T, TiB - tebibyte - P, PiB - pebibyte - E, EiB - exbibyte

Valid SI units are: - kB, KB - kilobyte - MB - megabyte - GB - gigabyte - TB - terabyte - PB - petabyte - EB - exabyte

NOTE: Accepts both IEC and SI units.

func (ByteSizeSI) MarshalJSON

func (b ByteSizeSI) MarshalJSON() ([]byte, error)

func (ByteSizeSI) MarshalText

func (b ByteSizeSI) MarshalText() ([]byte, error)

func (ByteSizeSI) String

func (b ByteSizeSI) String() string

func (*ByteSizeSI) UnmarshalJSON

func (b *ByteSizeSI) UnmarshalJSON(data []byte) error

func (*ByteSizeSI) UnmarshalText

func (b *ByteSizeSI) UnmarshalText(data []byte) error

type Clock

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

func NewClock

func NewClock(hour, minute, second int) Clock

func ParseClock

func ParseClock(s string) (c Clock, err error)

func (Clock) Hour

func (c Clock) Hour() int

func (Clock) MarshalJSON

func (c Clock) MarshalJSON() ([]byte, error)

func (Clock) MarshalText

func (c Clock) MarshalText() ([]byte, error)

func (Clock) Minute

func (c Clock) Minute() int

func (Clock) Second

func (c Clock) Second() int

func (Clock) String

func (c Clock) String() string

func (*Clock) UnmarshalJSON

func (c *Clock) UnmarshalJSON(b []byte) error

func (*Clock) UnmarshalText

func (c *Clock) UnmarshalText(b []byte) error

type Duration

type Duration time.Duration

Duration is time.Duration with additional day unit (`d`) during parsing and with JSON and Text (un)marshaling support.

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type TimeRate added in v0.2.1

type TimeRate struct {
	Period time.Duration
	Units  int
}

TimeRate represents a quantity per time period.

func ParseTimeRate added in v0.2.1

func ParseTimeRate(s string) (r TimeRate, err error)

ParseTimeRate parses a time rate string in the format "units/duration", such as "100/s", "42/1s", "1000/5m", "50/500ms", "10/.2s" or "100/1s200ms".

func (TimeRate) MarshalJSON added in v0.2.1

func (r TimeRate) MarshalJSON() ([]byte, error)

func (TimeRate) MarshalText added in v0.2.1

func (r TimeRate) MarshalText() ([]byte, error)

func (TimeRate) String added in v0.2.1

func (r TimeRate) String() string

func (*TimeRate) UnmarshalJSON added in v0.2.1

func (r *TimeRate) UnmarshalJSON(data []byte) error

func (*TimeRate) UnmarshalText added in v0.2.1

func (r *TimeRate) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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