commons

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CONTEXT_KEY_CHAINID = "chain"
View Source
const CONTEXT_KEY_LOGGER = "logger"

Variables

View Source
var MAINNET = "MAINNET"

Functions

func ChainIdToString

func ChainIdToString(chainId *proto.ChainId) string

func ContextWithLogger added in v0.0.6

func ContextWithLogger(ctx context.Context, log *slog.Logger) context.Context

func EitherSlice added in v0.0.6

func EitherSlice[T any](a, b []T) []T

func EitherStr added in v0.0.6

func EitherStr(a, b string) string

func FixField added in v0.0.6

func FixField[T any](raw map[string]any, path []string, fix func(*T) error) error

func FixJsonFields added in v0.0.6

func FixJsonFields(input []byte, ignoreMissing bool, fixes ...any) ([]byte, error)

FixJsonFields applies a series of fixes to the JSON fields in the input byte slice. To inject into UnmarshalJSON method of wrapper struct It takes a variadic number of fixes, where each fix is a pair of path and fix function. The path is a slice of strings representing the path to the field in the JSON structure. If ignoreMissing is set to true, the function will ignore fields that do not exist in the JSON structure. The function returns the modified JSON byte slice and an error if any occurred during the fixing process.

func FixerHexStripLeadingZeros added in v0.0.6

func FixerHexStripLeadingZeros(s *string) error

func FixerZeroHash added in v0.0.6

func FixerZeroHash(s *string) error

func FixerZeroUint64 added in v0.0.6

func FixerZeroUint64(s *string) error

func Hex2Int

func Hex2Int(hexStr string) (uint64, error)

func Hex2Uint64OrZero

func Hex2Uint64OrZero(hexStr string) uint64

func LabelsToMap added in v0.0.6

func LabelsToMap(labels []any) map[string]string

func LoggerFromContext added in v0.0.6

func LoggerFromContext(ctx context.Context, args ...any) *slog.Logger

func StringToChainId

func StringToChainId(chainId string) *proto.ChainId

func TrimLeftStrZeros added in v0.0.6

func TrimLeftStrZeros(s string) string

Types

type Config

type Config struct {
	// The port for the server to listen on
	Port int `json:"port"`

	// The host for the server to listen on
	Host string `json:"host"`
}

type ErrFieldNotExist added in v0.0.6

type ErrFieldNotExist struct {
	Path []string
}

func (*ErrFieldNotExist) Error added in v0.0.6

func (e *ErrFieldNotExist) Error() string

type UInt64HexString

type UInt64HexString uint64

func (UInt64HexString) AsNumber

func (v UInt64HexString) AsNumber() uint64

func (UInt64HexString) MarshalJSON

func (v UInt64HexString) MarshalJSON() ([]byte, error)

func (*UInt64HexString) UnmarshalJSON

func (v *UInt64HexString) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
conv

Jump to

Keyboard shortcuts

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