utils

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 14 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 AddQueryParam

func AddQueryParam(u, k string, v interface{}) string

AddQueryParam adds a query parameter to a URL.

func AddQueryParams

func AddQueryParams(u string, params map[string]interface{}) string

AddQueryParams adds query parameters to a URL.

func AnyToString

func AnyToString(v interface{}) string

AnyToString converts any type to string

func DownloadFile

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

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

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 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 ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts string to snake case.

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