utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 ColorMarshal

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

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.

func PrettyPrintByte

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

PrettyPrintByte ...

func PrettyPrintJSON

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

PrettyPrintJSON ...

func Retry

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 ToHex

func ToHex(input []byte) string

ToHex converts a byte array to its string representation in hexadecimal

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

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

func NewColorFormatter() *ColorFormatter

NewColorFormatter ...

func (*ColorFormatter) ColorMarshal

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

ColorMarshal ...

type RetryCallback

type RetryCallback func(interface{}) bool

RetryCallback ...

Jump to

Keyboard shortcuts

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