utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmailAddress = errors.New("invalid email address")
	ErrInvalidIcanSuffix   = errors.New("invalid ICAN suffix")
)

Functions

func AmountToFloat64

func AmountToFloat64(amount uint64, decimals uint8) float64

AmountToFloat64 converts amount lamports to float64 with given decimals.

func AmountToString

func AmountToString(amount uint64, decimals uint8) string

AmountToString converts amount lamports to string with given decimals.

func AmountToUint64

func AmountToUint64(amount float64, decimals uint8) uint64

AmountToUint64 converts amount from float64 to uint64 with given decimals.

func AnyToString

func AnyToString(v interface{}) string

AnyToString converts any type to string

func Base58ToBytes

func Base58ToBytes(s string) ([]byte, error)

Base58ToBytes converts base58 string to bytes.

func Base64ToBytes

func Base64ToBytes(s string) ([]byte, error)

Base64ToBytes converts base64 string to bytes.

func BytesToBase58

func BytesToBase58(b []byte) string

BytesToBase58 converts bytes to base58 string.

func BytesToBase64

func BytesToBase64(b []byte) string

BytesToBase64 converts bytes to base64 string.

func DownloadFile

func DownloadFile(url string) ([]byte, error)

DownloadFile downloads the file from the given URL and returns the bytes.

func Float64ToString

func Float64ToString(amount float64) string

Float64ToString converts float64 to string with minimum number of decimals. For example, 1.000000000 will be converted to "1", 1.100000000 will be converted to "1.1".

func GetFileByPath

func GetFileByPath(path string) ([]byte, error)

GetFileByPath returns the file bytes from the given path. If the path is a URL, it will download the file and return the bytes. If the path is a local file, it will read the file and return the bytes.

func GetFileTypeByURI

func GetFileTypeByURI(uri string) string

GetFileTypeByURI returns the file type of the given URI

func GetVarType

func GetVarType(v interface{}) string

GetVarType returns the type of the given variable as a string.

func IntAmountToFloat64

func IntAmountToFloat64(amount int64, decimals uint8) float64

IntAmountToFloat64 converts int64 amount lamports to float64 with given decimals.

func ParseFileSize

func ParseFileSize(s string) (int64, error)

Parse file size from string to int64

func Pointer

func Pointer[T any](v T) *T

Pointer is a helper to make a pointer to the given value.

func PrettyPrint

func PrettyPrint(v ...interface{})

PrettyPrint prints the given interface in a pretty format

func PrettyString

func PrettyString(v interface{}) string

PrettyString returns the given interface in a pretty format

func SanitizeEmail

func SanitizeEmail(s string) (string, error)

SanitizeEmail cleans email address from dots, dashes, etc

func StructToUrlValues

func StructToUrlValues(v interface{}) (url.Values, error)

StructToUrlValues converts a struct to a url.Values object.

func TrimRightZeros

func TrimRightZeros(str string) string

TrimRightZeros trims trailing zeros from string.

func TrimStringBetween

func TrimStringBetween(str, start, end string) string

Trim string between two substrings and return the string without it and substrings.

func UcFirst

func UcFirst(s string) string

UcFirst capitalizes first letter of a string

Types

This section is empty.

Jump to

Keyboard shortcuts

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