# README
Core
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.
# Packages
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 config contains the configuration required to run a node.
Package dbcommon provides common database functionality.
Package dockerutil contains facilities for programs to add context to docker tests.
Package ginhelper provides some common functionality across gin servers.
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 metrics implements a metrics dashboard with either.
Package mocktesting is used for mocking out the testing.T interface.
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 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 testsuite contains the standard test suite.
Package threaditer extends iter with a mutex for thread safe use.
# Functions
ArePointersEqual returns true if the given pointers are equal.
BigToDecimals converts a big to decimals.
BytesToJSONString converts a 32 bit array to a JSON string without escapes, newlines, etc.
BytesToSlice converts a 32 bit array to a slice slice.
ChunkSlice takes a slice of any ordered type (like int, float64, string, etc.) and divides it into chunks of a specified size.
CopyBigInt creates a copy of a big int without mutating the original.
CopyFile copies a file from src to dest and preserves its permissions.
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.
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.
GetEnv gets an environment variable.
GetEnvBool gets an environment variable as a bool.
GetEnvInt gets an environment variable as an int.
HasEnv checks if an environment variable is set.
IsTest returns true if the current process is a test.
PtrSlice converts every item in the slice to a pointer.
PtrTo returns a pointer to the given value.
RandomItem is a generic function to get a random item from a slice.
SleepWithContext will wait for the timer duration to expire, or the context is canceled.
ToSlice converts any number of items of any type to a slice containing those items.
# Variables
LogLevels stores available log levels in serverity order.