util

package
v0.2.25-beta.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 15 Imported by: 4

Documentation

Overview

Package util provides common utility functions.

Index

Constants

View Source
const (
	EnvCi        = "CI"
	EnvOsWindows = "windows"
)

Variables

View Source
var (
	ErrSyntax        = errors.New("invalid hex string")
	ErrMissingPrefix = errors.New("hex string without 0x prefix")
	ErrOddLength     = errors.New("hex string of odd length")
	ErrUint64Range   = errors.New("hex number > 64 bits")
)

Errors.

Functions

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. Parameter s may be prefixed with "0x".

func IsCi

func IsCi() bool

IsCi checks if we're running in CI.

func IsWindows

func IsWindows() bool

IsWindows checks if we're running on Windows.

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the smaller of the two inputs, both of type int.

func Uint64ToBytesBigEndian

func Uint64ToBytesBigEndian(i uint64) []byte

Uint64ToBytesBigEndian returns the byte representation of a uint64, using big endian encoding (which is not the default for spacemesh).

func UnmarshalFixedJSON

func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error

UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalJSON method for fixed-size types.

func UnmarshalFixedText

func UnmarshalFixedText(typename string, input, out []byte) error

UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.

Types

type Bytes

type Bytes []byte

Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Bytes) String

func (b Bytes) String() string

String returns the hex encoding of b.

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type MockGrpcServer added in v1.0.0

type MockGrpcServer struct {
	*grpc.Server
	Port uint16
	// contains filtered or unexported fields
}

MockGrpcServer allows for simulating a GRPC server in tests. Typical usage: ``` gtw := NewMockGrpcServer(t) <register required GRPC services> var eg errgroup.Group eg.Go(gtw.Serve) t.Cleanup(func() { require.NoError(t, eg.Wait()) }) t.Cleanup(gtw.Stop) ``` .

func NewMockGrpcServer added in v1.0.0

func NewMockGrpcServer(t testing.TB) *MockGrpcServer

func (*MockGrpcServer) Serve added in v1.0.0

func (s *MockGrpcServer) Serve() error

func (*MockGrpcServer) Target added in v1.0.0

func (s *MockGrpcServer) Target() string

Jump to

Keyboard shortcuts

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