meter

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 4 Imported by: 3

README

meter storage metering

storage metering,like B,KB,MB,GB,TB,PB,EB

GoDoc Go.Dev reference Build Status codecov Action Status Go Report Card License Tag

Features

  1. support human string like B,KB,MB,GB,TB,PB,EB
  2. support parse string unit below:
    • "empty",b,byte,
    • k,kb,kilo,kilobyte
    • m,mb,mega,megabyte,megabytes
    • g,gb,giga,gigabyte,gigabytes
    • t,tb,tera,terabyte,terabytes
    • p,pb,peta,petabyte,petabytes
    • e,eb,exa,exabyte,exabytes

Installation

  1. You can use the below Go command to install meter.
    go get -u github.com/things-go/meter
  1. Import it in your code.
    import "github.com/things-go/meter"

Quick start

package main

import (
	"fmt"

	"github.com/things-go/meter"
)

func main() {
	value, _ := meter.ParseBytes("2.99TB")
	s := meter.HumanSize(value)
	fmt.Println(value)
	fmt.Println(s)

	// output:
	// 3287539767050
	// 2.99TB
}

Reference

Donation

if package help you a lot,you can support us by:

Alipay

alipay

WeChat Pay

wxpay

Documentation

Overview

Package meter storage metering

Index

Examples

Constants

View Source
const (
	Byte  = 1
	KByte = Byte << 10
	MByte = KByte << 10
	GByte = MByte << 10
	TByte = GByte << 10
	PByte = TByte << 10
	EByte = PByte << 10
)

Storage unit constants.

Variables

This section is empty.

Functions

func HumanSize

func HumanSize(bytes uint64) (s string)

HumanSize human readable string

Example
value, _ := ParseBytes("2.99TB")
s := HumanSize(value)
fmt.Println(value)
fmt.Println(s)
Output:

3287539767050
2.99TB

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes parse a human string to byte

Types

type ByteSize

type ByteSize uint64

ByteSize byte size

func (ByteSize) Bytes

func (b ByteSize) Bytes() uint64

Bytes to byte

func (ByteSize) EBytes

func (b ByteSize) EBytes() float64

EBytes to ebyte

func (ByteSize) GBytes

func (b ByteSize) GBytes() float64

GBytes to gigabyte

func (ByteSize) HumanSize

func (b ByteSize) HumanSize() string

HumanSize human readable string

func (ByteSize) KBytes

func (b ByteSize) KBytes() float64

KBytes to kilobyte

func (ByteSize) MBytes

func (b ByteSize) MBytes() float64

MBytes to megabyte

func (ByteSize) MarshalText

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

MarshalText marshal to text

func (ByteSize) PBytes

func (b ByteSize) PBytes() float64

PBytes to petabyte

func (ByteSize) String

func (b ByteSize) String() string

String to string like xxB,xxKB,xxMB,xxGB,xxTB,xxPB,xxEB

func (ByteSize) TBytes

func (b ByteSize) TBytes() float64

TBytes to terabyte

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(t []byte) error

UnmarshalText unmarshal to ByteSize

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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