utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 30 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SSPrefix        = []byte{0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45}
	SubstratePrefix = []byte{0x2a}
	CessPrefix      = []byte{0x50, 0xac}
)

Functions

func BytesToBloomFilter added in v0.4.32

func BytesToBloomFilter(val []byte) (pattern.BloomFilter, error)

func BytesToFileHash added in v0.4.32

func BytesToFileHash(val []byte) (pattern.FileHash, error)

func BytesToPoISKeyInfo added in v0.4.32

func BytesToPoISKeyInfo(g, n []byte) (pattern.PoISKeyInfo, error)

func BytesToWorkPublickey added in v0.4.32

func BytesToWorkPublickey(val []byte) (pattern.WorkerPublicKey, error)

func CalcFileSHA256

func CalcFileSHA256(f *os.File) (string, error)

CalcFileSHA256 is used to calculate the sha256 value of the file type.

func CalcFileSHA256Bytes

func CalcFileSHA256Bytes(f *os.File) ([]byte, error)

CalcFileSHA256 is used to calculate the sha256 value of the file type.

func CalcMD5

func CalcMD5(data string) ([]byte, error)

CalcSHA256 is used to calculate the sha256 value of the data.

func CalcPathSHA256

func CalcPathSHA256(fpath string) (string, error)

CalcPathSHA256 is used to calculate the sha256 value of a file with a given path.

func CalcPathSHA256Bytes

func CalcPathSHA256Bytes(fpath string) ([]byte, error)

CalcPathSHA256 is used to calculate the sha256 value of a file with a given path.

func CalcSHA256

func CalcSHA256(data []byte) (string, error)

CalcSHA256 is used to calculate the sha256 value of the data.

func CheckBucketName

func CheckBucketName(name string) bool

func CheckDomain

func CheckDomain(name string) error

CheckDomain returns an error if the domain name is not valid. See https://tools.ietf.org/html/rfc1034#section-3.5 and https://tools.ietf.org/html/rfc1123#section-2.

func CompareSlice

func CompareSlice(s1, s2 []byte) bool

func DateTimeToUnix added in v0.4.28

func DateTimeToUnix(t string) (int64, error)

func EncodePublicKeyAsCessAccount

func EncodePublicKeyAsCessAccount(publicKey []byte) (string, error)

func EncodePublicKeyAsSubstrateAccount

func EncodePublicKeyAsSubstrateAccount(publicKey []byte) (string, error)

func FildIpv4 added in v0.4.32

func FildIpv4(data []byte) (string, bool)

func GenerateFile added in v0.5.1

func GenerateFile(mb uint32, path string) error

func GetDirFreeSpace

func GetDirFreeSpace(dir string) (uint64, error)

func GetRandomcode

func GetRandomcode(length uint8) string

Generate random password

func GetSysMemAvailable

func GetSysMemAvailable() (uint64, error)

func GetUnixTimeAtZeroToday added in v0.4.28

func GetUnixTimeAtZeroToday() int64

func IsIPv4

func IsIPv4(ipAddr string) bool

IsIPv4 is used to determine whether ipAddr is an ipv4 address

func IsIPv6

func IsIPv6(ipAddr string) bool

IsIPv6 is used to determine whether ipAddr is an ipv6 address

func IsInterfaceNIL added in v0.4.32

func IsInterfaceNIL(i interface{}) bool

func IsIntranetIpv4 added in v0.4.32

func IsIntranetIpv4(ipv4 string) (bool, error)

func IsPortInUse added in v0.4.32

func IsPortInUse(port int) bool

func IsWorkerPublicKeyAllZero added in v0.4.32

func IsWorkerPublicKeyAllZero(puk pattern.WorkerPublicKey) bool

func NumsToByteStr

func NumsToByteStr[T constraints.Unsigned](nums []T, opts map[string]bool) (string, error)

NumsToByteStr utility function takes an array of unsigned integers and output the corresponding byte string representing it. For example: `[18, 15]` to `120F`.

For `opts` in second parameter it is a map expecting:

  • `space` bool: whether to add a space between each byte, default to `false`
  • `prefix` bool: whether to add `0x` as the prefix, default to `false`
  • `uppercase` bool: whether to display hexadecimal in upper case, default to `true`

If there is an integer larger than 255 in the array, an error is returned.

func NumsToByteStrDefault

func NumsToByteStrDefault[T constraints.Unsigned](nums []T) (string, error)

func ParsingPublickey

func ParsingPublickey(address string) ([]byte, error)

func PingNode added in v0.5.1

func PingNode(addr string, timeout time.Duration) (time.Duration, error)

PingNode be used to ping target node by ICMP protocol, It returns the TTL from target node. Requires root privileges to use.

func RandSlice

func RandSlice(slice interface{})

func RandStr

func RandStr(n int) string

func RecoverError

func RecoverError(err interface{}) error

RecoverError is used to record the stack information of panic

func TraceRoute added in v0.5.1

func TraceRoute(ip string, timeout time.Duration) (int, time.Duration, error)

TraceRoute be used to trace route to target node by ICMP protocol, It returns the distance and TTL from target node. Requires root privileges to use

func VerityAddress

func VerityAddress(address string, prefix []byte) error

func WriteBufToFile

func WriteBufToFile(buf []byte, file string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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