utils

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrContainsStr

func ArrContainsStr(array []string, str string) bool

ArrContainsStr checks if a string is in a string array

func Convert

func Convert[T any](value string, convertor func(string) (T, error), defaultValue ...T) (*T, error)

func ConvertBytesToHumanReadableSize

func ConvertBytesToHumanReadableSize(bytes int) string

ConvertBytesToHumanReadableSize converts the given integer size in bytes to a human-readable string format. If the size is 0, it returns "0B". It uses the logarithmic calculation to determine the appropriate unit prefix (e.g., KB, MB, GB, etc.), and formats the value with two decimal places before appending the unit suffix. The units slice contains the available unit prefixes: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]. Note: The function assumes that the given size is a positive integer.

func CopyIOZeroAlloc

func CopyIOZeroAlloc(w io.Writer, r io.Reader) (int64, error)

func FilePathToIOReader

func FilePathToIOReader(filePath string) (io.Reader, error)

func GenXid

func GenXid() string

func HumanReadableSizeToBytes

func HumanReadableSizeToBytes(humanReadableString string) int

HumanReadableSizeToBytes returns integer size of bytes from human-readable string, ex. 42kb, 42M Returns 0 if string is unrecognized

Types

type DataEncryptionUtils

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

func UseEncryption

func UseEncryption(key string) *DataEncryptionUtils

func (*DataEncryptionUtils) Decrypt

func (deu *DataEncryptionUtils) Decrypt(data string) ([]byte, error)

func (*DataEncryptionUtils) Encrypt

func (deu *DataEncryptionUtils) Encrypt(data []byte) (string, error)

Jump to

Keyboard shortcuts

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