fmtutil

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fmtutil provide some format util functions.

Index

Constants

View Source
const (
	OneKByte = 1024
	OneMByte = 1024 * 1024
	OneGByte = 1024 * 1024 * 1024
)

data size

Variables

This section is empty.

Functions

func ArgsWithSpaces

func ArgsWithSpaces(vs []any) (message string)

ArgsWithSpaces it like Println, will add spaces for each argument

func DataSize

func DataSize(size uint64) string

DataSize format bytes number friendly.

Usage:

file, err := os.Open(path)
fl, err := file.Stat()
fmtSize := DataSize(fl.Size())

func FormatDuration added in v0.7.2

func FormatDuration(d time.Duration) string

FormatDuration Formatting time consumption is clock format 格式化时间消耗为时钟格式 eg: 90 * time.Second => "01:30"

func HowLongAgo

func HowLongAgo(sec int64) string

HowLongAgo format a seconds, got how lang ago

func HumanSize

func HumanSize(size uint64) string

HumanSize alias of the DataSize

func ParseByte

func ParseByte(sizeStr string) uint64

ParseByte converts size string like 1GB/1g or 12mb/12M into an unsigned integer number of bytes

func PrettyJSON

func PrettyJSON(v any) (string, error)

PrettyJSON get pretty Json string

func SizeToString

func SizeToString(size uint64) string

SizeToString alias of the DataSize

func StringOrJSON

func StringOrJSON(v any) ([]byte, error)

StringOrJSON to string or encode pretty JSON data to json bytes.

func StringToByte

func StringToByte(sizeStr string) uint64

StringToByte alias of the ParseByte

Types

This section is empty.

Jump to

Keyboard shortcuts

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