unit

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package unit contains types and methods for dealing with units of various types. Currently supports metric data units.

Index

Constants

View Source
const (
	Byte     = DataUnit(1)
	Kilobyte = Byte * 1000
	Megabyte = Kilobyte * 1000
	Gigabyte = Megabyte * 1000
	Terabyte = Gigabyte * 1000
	Petabyte = Terabyte * 1000
)

Supported DataUnit values.

Variables

View Source
var (
	// ErrInvalidDataUnit is the error given when parsing a data unit that contains invalid
	// characters.
	ErrInvalidDataUnit = errors.New("invalid data unit")

	// ErrUnknownDataUnit is the error given when parsing a data unit and the unit string does not match
	// any known units.
	ErrUnknownDataUnit = errors.New("unknown data unit")
)

Functions

This section is empty.

Types

type DataUnit

type DataUnit int

The DataUnit type contains a metric representation of a unit of data, ie bytes, kilobytes etc.

func ParseDataUnit

func ParseDataUnit(str string) (DataUnit, error)

ParseDataUnit attempts to return a DataUnit corresponding to the provided string. Current values are supported from byte to petabyte:

10B: 10 bytes 10kB: 10 kilobytes 20MB: 20 megabytes 5GB: 5 gigabytes 10TB: 10 terabytes 1PB: 1 petabyte.

func (DataUnit) String

func (du DataUnit) String() string

Jump to

Keyboard shortcuts

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