utils

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 20 Imported by: 11

Documentation

Index

Constants

View Source
const (
	ISO_8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
)

Variables

View Source
var (
	ISO_8859_1   = charmap.ISO8859_1.String() // ISO 8859-1
	ISO_8859_2   = charmap.ISO8859_2.String() // ISO 8859-2
	ISO_8859_3   = charmap.ISO8859_3.String() // ISO 8859-3
	ISO_8859_4   = charmap.ISO8859_4.String() // ISO 8859-4
	MACINTOSH    = charmap.Macintosh.String() // Macintosh
	UTF_8        = "utf-8"
	WINDOWS_1252 = charmap.Windows1252.String() // Windows 1252
)

Encoding formats

Functions

func ByteArrayToFloat added in v1.1.3

func ByteArrayToFloat(barray []byte) float64

ByteArrayToFloat converts the passed byte array to a float64.

func ByteArrayToInt

func ByteArrayToInt(bytes []byte) int

ByteArrayToInt converts the passed byte array to a int.

func ByteArrayToUint

func ByteArrayToUint(barray []byte) uint64

ByteArrayToUint converts the passed byte array into a uint64.

func ByteArrayToUint8

func ByteArrayToUint8(barray []byte) uint8

ByteArrayToUint8 converts the passed byte array into a uint8.

func Capitalize added in v1.3.4

func Capitalize(sentence string) string

Capitalize add an upper case at the beginning of the sentence

func Chunk added in v1.4.8

func Chunk(slice []string, chunkSize int) [][]string

Chunk splits a slice of strings into the number of passed chunks

func ColorMarshal added in v1.3.9

func ColorMarshal(jsonObj interface{}) ([]byte, error)

ColorMarshal marshals JSON data with default options

func ContainString

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

ContainString returns true if the passed slice of strings contains the passed string value

func DateFormat added in v1.4.10

func DateFormat(t time.Time, layout string) string

DateFormat formats the passed time to the Java-notated layout, eg. `yyyy-MM-dd`

func DateLayoutJava2Go added in v1.4.10

func DateLayoutJava2Go(layout string) string

DateLayoutJava2Go transforms a Java notation to its Golang equivalent

func EuclideanDivision

func EuclideanDivision(numerator, denominator int) (quotient, remainder int, err error)

EuclideanDivision returns the integer tuple (quotient, remainder) from the division of the past integers

func FindClosest

func FindClosest(arr []*big.Int, target *big.Int) (*big.Int, bool)

FindClosest returns the closest number to the target in the passed array of numbers see https://www.geeksforgeeks.org/find-closest-number-array/

func Flatten

func Flatten(arrayOfByteArray [][]byte) (concat []byte)

Flatten takes an array of byte array and makes it a byte array

func FloatToByteArray added in v1.1.3

func FloatToByteArray(data float64) (barray []byte)

FloatToByteArray converts the passed float64 into a byte array.

func FromHex

func FromHex(input string) ([]byte, error)

FromHex tries to convert an hexadecimal representation of a value to its corresponding byte array

func IntToByteArray

func IntToByteArray(data int) []byte

IntToByteArray converts the passed integer to a byte array.

func IsPointer

func IsPointer(item interface{}) bool

IsPointer returns `true` if the passed item is a pointer, not a value

func IsValue

func IsValue(item interface{}) bool

IsValue returns `true` if the passed item is a value, not a pointer

func Must

func Must(bytes []byte, err error) []byte

Must only returns the byte array from the argument tuple (byte array, error).

Use with caution, ie. only when you are absolutely certain that it shouldn't lead to a panic, or that if it leads to a panic it means that there's no way the program should work anyway. For example, `bytes := utils.Must(hex.DecodeString(h))` where `h` is an hexadecimal string hash for sure.

func PrettyPrintByte

func PrettyPrintByte(b []byte) ([]byte, error)

PrettyPrintByte ...

func PrettyPrintJSON

func PrettyPrintJSON(input interface{}) ([]byte, error)

PrettyPrintJSON ...

func Retry added in v1.3.9

func Retry(numberOfRetry int, duration int, callback RetryCallback, args interface{}, needToExit bool, then RetryCallback, thenArgs interface{})

Retry is a function supposed to be called in a goroutine to execute a callback a number of time with a given time between each repetition. duration is in Millisecond.

func Reverse added in v1.7.2

func Reverse(str string) string

Reverse write the passed string backwards

func ToHex

func ToHex(input []byte) string

ToHex converts a byte array to its string representation in hexadecimal

func ToUTF8 added in v1.4.3

func ToUTF8(encoded, format string) (decoded string, err error)

ToUTF8 transforms a encoded string in the passed encoding format to a UTF-8 string

NB: For now, it only supports ISO 8859-1, ISO 8859-2, ISO 8859-3, ISO 8859-4, Macintosh and Windows 1252 formats

func Uint8ToByteArray

func Uint8ToByteArray(data uint8) (barray []byte)

Uint8ToByteArray converts the passed uint8 into a byte array.

func UintToByteArray

func UintToByteArray(data uint64) (barray []byte)

UintToByteArray converts the passed integer into a byte array.

Types

type ColorFormatter added in v1.3.9

type ColorFormatter struct {
	KeyColor        *color.Color
	StringColor     *color.Color
	BoolColor       *color.Color
	NumberColor     *color.Color
	NullColor       *color.Color
	StringMaxLength int
	Indent          int
	DisabledColor   bool
	RawStrings      bool
}

ColorFormatter ...

func NewColorFormatter added in v1.3.9

func NewColorFormatter() *ColorFormatter

NewColorFormatter ...

func (*ColorFormatter) ColorMarshal added in v1.3.9

func (f *ColorFormatter) ColorMarshal(jsonObj interface{}) ([]byte, error)

ColorMarshal ...

type DivisionByZeroError added in v1.1.2

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

DivisionByZeroError ...

func NewDivisionByZeroError added in v1.1.2

func NewDivisionByZeroError() *DivisionByZeroError

func (DivisionByZeroError) Error added in v1.1.2

func (e DivisionByZeroError) Error() string

type RetryCallback added in v1.3.9

type RetryCallback func(interface{}) bool

RetryCallback ...

Jump to

Keyboard shortcuts

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