utils

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: Apache-2.0 Imports: 34 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Decimal
	KB = 1000
	MB = 1000 * KB
	GB = 1000 * MB
	TB = 1000 * GB
	PB = 1000 * TB

	// Binary
	KiB = 1024
	MiB = 1024 * KiB
	GiB = 1024 * MiB
	TiB = 1024 * GiB
	PiB = 1024 * TiB
)

See: http://en.wikipedia.org/wiki/Binary_prefix

View Source
const (
	TagNameYaml = "yaml"
	TagNameJSON = "json"
	TagNameNone = ""
)

contants

Variables

This section is empty.

Functions

func AppendFile

func AppendFile(dir, filename string, data []byte) error

AppendFile func

func ByteToMap

func ByteToMap(data []byte) (map[string]interface{}, error)

ByteToMap converts []byte map[string]interface{}

func ByteToStruct

func ByteToStruct(data []byte, out interface{}) error

ByteToStruct converts []byte to interface

func ContainsString

func ContainsString(slice []string, value string) bool

ContainsString returns the available status

func CopyFile

func CopyFile(src, dst string) error

copies from a location to another location

func CopyFileForce

func CopyFileForce(src, dst string, overwrite bool) error

copies from a location to another location with optional overwrite

func CreateDir

func CreateDir(dir string) error

CreateDir func

func CustomSize

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

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

func DeepClone

func DeepClone(data interface{}) interface{}

DeepClone a interface

func FindItem

func FindItem(slice []string, value string) (int, bool)

FindItem returns the availability status and location

func GetMapValue

func GetMapValue(m map[string]interface{}, key string, defaultValue interface{}) interface{}

GetMapValue returns fetch and returns with a key. if not available returns default value

func GetMapValueString

func GetMapValueString(m map[string]interface{}, key string, defaultValue string) string

GetMapValueString returns value, if not available returns defaultValue

func IsDirExists

func IsDirExists(dirname string) bool

IsDirExists checks the directory availability

func IsFileExists

func IsFileExists(filename string) bool

IsFileExists checks the file availability

func JoinMap

func JoinMap(dst, src map[string]interface{})

JoinMap joins two maps. put all the values into 'dst' map from 'src' map

func JoinStringMap

func JoinStringMap(dst, src map[string]string)

JoinStringMap joins two string maps. put all the values into 'dst' map from 'src' map

func ListDirs

func ListDirs(dir string) ([]types.File, error)

ListDirs func

func ListFiles

func ListFiles(dir string) ([]types.File, error)

list the files recursively

func MapToStruct

func MapToStruct(tagName string, in map[string]interface{}, out interface{}) error

MapToStruct converts string to struct

func ParseSize

func ParseSize(sizeStr string) (int64, error)

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

func ParseSizeWithDefault

func ParseSizeWithDefault(size string, defaultSize int64) int64

ParseSizeWithDefault returns with default

func RandID

func RandID() string

RandID returns random id

func RandIDWithLength

func RandIDWithLength(length int) string

RandIDWithLength returns random id with supplied charset

func RandUUID

func RandUUID() string

RandUUID returns random uuid

func ReadFile

func ReadFile(dir, filename string) ([]byte, error)

ReadFile func

func RemoveDir

func RemoveDir(dir string) error

RemoveDir func

func RemoveFileOrEmptyDir

func RemoveFileOrEmptyDir(file string) error

RemoveFileOrEmptyDir func

func SmartSleep

func SmartSleep(duration time.Duration)

SmartSleep waits till the duration reaches

func StructToByte

func StructToByte(data interface{}) ([]byte, error)

StructToByte converts interface to []byte

func StructToMap

func StructToMap(data interface{}) map[string]interface{}

StructToMap converts struct to a map

func ToBinarySizeString

func ToBinarySizeString(size float64) string

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

func ToDecimalSizeString

func ToDecimalSizeString(size float64) string

ToDecimalSizeString with 2 decimal

func ToDecimalSizeStringWithPrecision

func ToDecimalSizeStringWithPrecision(size float64, precision int) string

ToDecimalSizeStringWithPrecision allows the size to be in any precision,

func ToDuration

func ToDuration(duration string, defaultDuration time.Duration) time.Duration

ToDuration converts the string duration to time.Duration, if failed returns the default

func ToStruct

func ToStruct(data []byte, out interface{}) error

ToStruct converts bytes to target struct

func UpdatePagination

func UpdatePagination(pagination *storageTY.Pagination) *storageTY.Pagination

UpdatePagination updates if nil

func ValidDuration

func ValidDuration(duration, defaultDuration string) string

ValidDuration verifies the duration, if it hits error returns the default duration

func WriteFile

func WriteFile(dir, filename string, data []byte) error

WriteFile func

Types

This section is empty.

Jump to

Keyboard shortcuts

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