core

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 15 Imported by: 56

README

Core

Go Reference Go Report Card

Core contains common libraries used across the synapse Go repositories.

Directory Structure

root
├── bytemap: Implements a map using `[]rune` or `[]byte` instead of `string`
├── commandline: Provides utilities for creating an interactive shell command for a [`cli`](github.com/urfave/cli) using the [`go-prompt`](github.com/c-bata/go-prompt) package.
├── config: Contains the configuration for the core package.
├── dbcommon: Contains common database utilities used with gorm.
├── dockerutil: Provides tools for working with Docker.
├── ginhelper: Contains a set of utilities for working with the Gin framework and a set of common middleware.
├── mapmutex: Implements a map that uses a mutex to protect concurrent access.
├── merkle: Provides a go based merkle tree implementation.
├── metrics: Provides a set of utilities for working with metrics/otel tracing.
├── mocktesting: Provides a mocked tester for use with `testing.TB`
├── observer(deprecated): Provides an interface for adding/removing listeners.
├── processlog: Provides a way to interact with detatched processes as streams.
├── retry: Retries a function until it succeeds or the timeout is reached. This comes with a set of backoff strategies/options.
├── server: Provides a context-safe server that can be used to start/stop a server.
├── testsuite: Provides a wrapper around testify/suite.
├── threaditer: Provides a thread-safe generic iterator for a slice.

Documentation

Overview

Package core contains the core dependencies

Index

Examples

Constants

This section is empty.

Variables

LogLevels stores available log levels in serverity order.

Functions

func ArePointersEqual added in v0.0.52

func ArePointersEqual(a, b interface{}) bool

ArePointersEqual returns true if the given pointers are equal. Will return false if either of the given values are not pointers. nolint: cyclop, forcetypeassert

func BigToDecimals added in v0.1.2

func BigToDecimals(bigInt *big.Int, decimals uint8) float64

BigToDecimals converts a big to decimals

func BytesToArray added in v1.9.0

func BytesToArray(bz []byte) ([32]byte, error)

BytesToArray converts a slice to a 32 length byte array.

func BytesToJSONString added in v0.6.0

func BytesToJSONString(bz []byte) (string, error)

BytesToJSONString converts a 32 bit array to a JSON string without escapes, newlines, etc.

func BytesToSlice

func BytesToSlice(bytes [32]byte) []byte

BytesToSlice converts a 32 bit array to a slice slice.

func ChunkSlice added in v0.0.82

func ChunkSlice[T any](slice []T, chunkSize int) [][]T

ChunkSlice takes a slice of any ordered type (like int, float64, string, etc.) and divides it into chunks of a specified size.

func CopyBigInt

func CopyBigInt(val *big.Int) *big.Int

CopyBigInt creates a copy of a big int without mutating the original.

func CopyFile added in v0.0.74

func CopyFile(src, dest string) error

CopyFile copies a file from src to dest and preserves its permissions.

func CopyPointer added in v0.1.4

func CopyPointer[T any](originalPtr *T) *T

CopyPointer is a generic function that takes a pointer of any type and returns a new pointer to a new value of the same type.

func ExpandOrReturnPath added in v0.0.6

func ExpandOrReturnPath(path string) string

ExpandOrReturnPath expands a homedir path, if it can't be expanded, the original dir is returned since on these systems homedir cannot be used anyway.

func GetEnv

func GetEnv(name, defaultVal string) string

GetEnv gets an environment variable. If it is not present, the default variable is used.

func GetEnvBool added in v0.0.70

func GetEnvBool(name string, defaultVal bool) bool

GetEnvBool gets an environment variable as a bool. If not found the default value is used.

func GetEnvInt

func GetEnvInt(name string, defaultVal int) int

GetEnvInt gets an environment variable as an int. if not found or cast the defaultVal is returned.

func HasEnv added in v0.0.43

func HasEnv(name string) bool

HasEnv checks if an environment variable is set.

func IsTest added in v0.0.11

func IsTest() bool

IsTest returns true if the current process is a test.

func PtrSlice added in v0.0.61

func PtrSlice[T any](slice []T) []*T

PtrSlice converts every item in the slice to a pointer.

Example
package main

import (
	"fmt"
	"github.com/ethereum/go-ethereum/common"
	"github.com/synapsecns/sanguine/core"
	"reflect"
)

func main() {
	res := core.PtrSlice([]common.Hash{})
	fmt.Println(reflect.TypeOf(res))
}
Output:

[]*common.Hash

func PtrTo added in v0.0.32

func PtrTo[T any](v T) *T

PtrTo returns a pointer to the given value.

Example
package main

import (
	"fmt"
	"github.com/ethereum/go-ethereum/common"
	"github.com/synapsecns/sanguine/core"
	"reflect"
)

func main() {
	res := core.PtrTo(common.Hash{})
	fmt.Println(reflect.TypeOf(res))
}
Output:

*common.Hash

func RandomItem added in v0.0.36

func RandomItem[T any](items []T) (res T, _ error)

RandomItem is a generic function to get a random item from a slice.

func SleepWithContext added in v0.0.43

func SleepWithContext(ctx context.Context, dur time.Duration) error

SleepWithContext will wait for the timer duration to expire, or the context is canceled. Which ever happens first. If the context is canceled the Context's error will be returned.

Expects Context to always return a non-nil error if the Done channel is closed. Note: this was taknen from the aws sdk, but modified to avoid the dependency in core.

func ToSlice added in v0.1.2

func ToSlice[T any](items ...T) []T

ToSlice converts any number of items of any type to a slice containing those items.

Types

This section is empty.

Directories

Path Synopsis
Package bytemap is an implementation of https://github.com/google/triemap/blob/main/bytemap.go with generic support for values
Package bytemap is an implementation of https://github.com/google/triemap/blob/main/bytemap.go with generic support for values
Package commandline contains common utilities for use across clis
Package commandline contains common utilities for use across clis
Package config contains the configuration required to run a node.
Package config contains the configuration required to run a node.
Package dbcommon provides common database functionality
Package dbcommon provides common database functionality
Package dockerutil contains facilities for programs to add context to docker tests.
Package dockerutil contains facilities for programs to add context to docker tests.
Package ginhelper provides some common functionality across gin servers.
Package ginhelper provides some common functionality across gin servers.
internal
assets
Package assets provides static assets we want to embed in the application in the main folder and documentation related assets in subfolders.
Package assets provides static assets we want to embed in the application in the main folder and documentation related assets in subfolders.
Package mapmutex provides an extensible, type-safe mutex implementation TODO: use generics
Package mapmutex provides an extensible, type-safe mutex implementation TODO: use generics
Package merkle provides the tools to create a merkle tree and keep track of its historical states.
Package merkle provides the tools to create a merkle tree and keep track of its historical states.
Package metrics implements a metrics dashboard with either
Package metrics implements a metrics dashboard with either
instrumentation
Package instrumentation provides a set of custom instruments for different providers.
Package instrumentation provides a set of custom instruments for different providers.
instrumentation/httpcapture
Package httpcapture provides an http.RoundTripper that captures requests and responses.
Package httpcapture provides an http.RoundTripper that captures requests and responses.
instrumentation/slackertrace
Package slackertrace provides a Slacker trace exporter for OpenTelemetry.
Package slackertrace provides a Slacker trace exporter for OpenTelemetry.
internal
Package internal contains internal constants for metrics package this is done in a separate package to avoid circular dependencies
Package internal contains internal constants for metrics package this is done in a separate package to avoid circular dependencies
localmetrics
Package localmetrics provides a local server for metrics.
Package localmetrics provides a local server for metrics.
logger
Package logger provides a logger interface and a null logger implementation.
Package logger provides a logger interface and a null logger implementation.
Package mocktesting is used for mocking out the testing.T interface.
Package mocktesting is used for mocking out the testing.T interface.
Package observer provides an observer implementation
Package observer provides an observer implementation
Package processlog contains an opinionated method for piping logs from external processes into stdout and readbale files for testing..
Package processlog contains an opinionated method for piping logs from external processes into stdout and readbale files for testing..
Package retry provides a simple yet powerful retry mechanism for Go.
Package retry provides a simple yet powerful retry mechanism for Go.
Package server provides a way to access a server TODO: consider moving this into gin helper
Package server provides a way to access a server TODO: consider moving this into gin helper
Package testsuite contains the standard test suite
Package testsuite contains the standard test suite
Package threaditer extends iter with a mutex for thread safe use
Package threaditer extends iter with a mutex for thread safe use

Jump to

Keyboard shortcuts

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