utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2020 License: MIT Imports: 9 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

Jump to

Keyboard shortcuts

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