Documentation
¶
Index ¶
- Variables
- func AllPermutations[S ~[]E, E any](s S) iter.Seq[iter.Seq2[int, E]]
- func Atof(s string) (float64, error)
- func CheckJSON[T any](contents []byte, e *ErrorLogger)
- func CommaKeyExpand[T any](in map[string]T) (map[string]T, error)
- func DeleteSliceElement[V any](s []V, i int) []V
- func DuplicateMap[K comparable, V any](m map[K]V) map[K]V
- func DuplicateSlice[V any](s []V) []V
- func FilterSeq[T any](seq iter.Seq[T], pred func(T) bool) iter.Seq[T]
- func FilterSlice[V any](s []V, pred func(V) bool) []V
- func FilterSliceInPlace[V any](s []V, pred func(V) bool) []V
- func GetLoggedRPCBandwidth() (int64, int64)
- func GetResourceReader(path string) (io.ReadCloser, error)
- func GetResourcesFS() fs.StatFS
- func Hash(r io.Reader) ([]byte, error)
- func HashString64(s string) uint64
- func InsertSliceElement[V any](s []V, i int, v V) []V
- func IsAllLetters(s string) bool
- func IsAllNumbers(s string) bool
- func IsRPCServerError(err error) bool
- func LoadResourceBytes(path string) []byte
- func MakeGOBClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec
- func MakeGOBServerCodec(conn io.ReadWriteCloser, lg *log.Logger) rpc.ServerCodec
- func MapContains[K comparable, V any](m map[K]V, pred func(K, V) bool) bool
- func MapLookupFunc[K comparable, V any](m map[K]V, pred func(K, V) bool) (K, V, bool)
- func MapSeq[T, U any](seq iter.Seq[T], f func(T) U) iter.Seq[U]
- func MapSeq2[K, V, K2, V2 any](seq iter.Seq2[K, V], f func(K, V) (K2, V2)) iter.Seq2[K2, V2]
- func MapSlice[F, T any](from []F, xform func(F) T) []T
- func ReduceMap[K comparable, V any, R any](m map[K]V, reduce func(K, V, R) R, initial R) R
- func ReduceSlice[V any, R any](s []V, reduce func(V, R) R, initial R) R
- func Select[T any](sel bool, a, b T) T
- func SelectInTwoEdits(str string, seq iter.Seq[string], dist1, dist2 []string) ([]string, []string)
- func SeqContains[T comparable](seq iter.Seq[T], v T) bool
- func SeqContainsFunc[T any](seq iter.Seq[T], check func(T) bool) bool
- func SliceReverseValues[Slice ~[]E, E any](s Slice) iter.Seq[E]
- func SliceReverseValues2[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]
- func SortedMapKeys[K constraints.Ordered, V any](m map[K]V) []K
- func StopShouting(orig string) string
- func TypeCheckJSON[T any](json interface{}) bool
- func UnmarshalJSON[T any](r io.Reader, out *T) error
- func UnmarshalJSONBytes[T any](b []byte, out *T) error
- func WalkResources(root string, ...) error
- func WrapText(s string, columnLimit int, indent int, wrapAll bool) (string, int)
- type AtomicBool
- type CompressedConn
- type ErrorLogger
- func (e *ErrorLogger) CheckDepth(d int)
- func (e *ErrorLogger) CurrentDepth() int
- func (e *ErrorLogger) Error(err error)
- func (e *ErrorLogger) ErrorString(s string, args ...interface{})
- func (e *ErrorLogger) HaveErrors() bool
- func (e *ErrorLogger) Pop()
- func (e *ErrorLogger) PrintErrors(lg *log.Logger)
- func (e *ErrorLogger) Push(s string)
- func (e *ErrorLogger) String() string
- type JSONChecker
- type LoggingClientCodec
- type LoggingConn
- type LoggingMutex
- type LoggingServerCodec
- type ObjectArena
- type OneOf
- type OrderedMap
- type PendingCall
- type Profiler
- type RPCClient
- type ResourceReadCloser
- type RingBuffer
- type RootFS
- type SingleOrArray
- type TransientMap
Constants ¶
This section is empty.
Variables ¶
var ErrRPCTimeout = errors.New("RPC call timed out")
var RXTotal, TXTotal int64
Functions ¶
func AllPermutations ¶ added in v0.11.5
AllPermutations returns an iterator over all permutations of the given slice. Each permutation can then be iterated over.
func Atof ¶
atof is a utility for parsing floating point values that sends errors to the logging system.
func CheckJSON ¶ added in v0.11.5
func CheckJSON[T any](contents []byte, e *ErrorLogger)
CheckJSON checks whether the provided JSON is syntactically valid and then typechecks it with respect to the provided type T.
func CommaKeyExpand ¶
Given a map from strings to some type T where the keys are assumed to be of the form "foo,bar,bat", return a new map where each comma-delineated string in the keys has its own entry in the returned map. Returns an error if a key is repeated.
func DeleteSliceElement ¶
DeleteSliceElement deletes the i-th element of the given slice, returning the resulting slice.
Note that the provided slice s is modified!
func DuplicateMap ¶
func DuplicateMap[K comparable, V any](m map[K]V) map[K]V
DuplicateMap returns a newly allocated map that stores copies of all the values in the given map.
func DuplicateSlice ¶
func DuplicateSlice[V any](s []V) []V
DuplicateSlice returns a newly-allocated slice that is a copy of the provided one.
func FilterSeq ¶ added in v0.11.9
FilterSeq applies uses the given predicate function to filter the elements given by a sequence iterator, returning an iterator over the filtered elements.
func FilterSlice ¶
FilterSlice applies the given filter function pred to the given slice, returning a new slice that only contains elements where pred returned true.
func FilterSliceInPlace ¶ added in v0.11.10
FilterSliceInPlace applies the given filter function pred to the given slice, returning a slice constructed from the provided slice's memory that only contains elements where pred returned true.
func GetLoggedRPCBandwidth ¶
func GetResourceReader ¶ added in v0.11.6
func GetResourceReader(path string) (io.ReadCloser, error)
func GetResourcesFS ¶ added in v0.11.6
func HashString64 ¶ added in v0.11.9
func InsertSliceElement ¶
InsertSliceElement inserts the given value v at the index i in the slice s, moving all elements after i one place forward.
func IsAllLetters ¶
func IsAllNumbers ¶
func IsRPCServerError ¶
func LoadResourceBytes ¶ added in v0.11.8
func MakeGOBClientCodec ¶
func MakeGOBClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec
func MakeGOBServerCodec ¶
func MakeGOBServerCodec(conn io.ReadWriteCloser, lg *log.Logger) rpc.ServerCodec
func MapContains ¶
func MapContains[K comparable, V any](m map[K]V, pred func(K, V) bool) bool
func MapLookupFunc ¶ added in v0.11.10
func MapLookupFunc[K comparable, V any](m map[K]V, pred func(K, V) bool) (K, V, bool)
func MapSlice ¶
func MapSlice[F, T any](from []F, xform func(F) T) []T
MapSlice returns the slice that is the result of applying the provided xform function to all the elements of the given slice.
func ReduceMap ¶
func ReduceMap[K comparable, V any, R any](m map[K]V, reduce func(K, V, R) R, initial R) R
ReduceMap applies the provided reduction function to the given map, starting with the provided initial value. The update rule applied is result=reduce(key, value, result), where the initial value of result is given by the initial parameter.
func ReduceSlice ¶
ReduceSlice applies the provided reduction function to the given slice, starting with the provided initial value. The update rule applied is result=reduce( value, result), where the initial value of result is given by the initial parameter.
func SelectInTwoEdits ¶ added in v0.11.10
Given a string iterator and a base string, return two arrays of strings from the iterator that are respectively within one or two edits of the base string. // https://en.wikipedia.org/wiki/Levenshtein_distance
func SeqContains ¶ added in v0.11.9
func SeqContains[T comparable](seq iter.Seq[T], v T) bool
func SeqContainsFunc ¶ added in v0.11.9
func SliceReverseValues ¶ added in v0.11.7
func SliceReverseValues2 ¶ added in v0.11.7
func SortedMapKeys ¶
func SortedMapKeys[K constraints.Ordered, V any](m map[K]V) []K
SortedMapKeys returns the keys of the given map, sorted from low to high.
func StopShouting ¶
StopShouting turns text of the form "UNITED AIRLINES" to "United Airlines"
func TypeCheckJSON ¶ added in v0.11.5
TypeCheckJSON returns a Boolean indicating whether the provided raw unmarshaled JSON values are type-compatible with the given type T.
func UnmarshalJSONBytes ¶ added in v0.11.8
Unmarshal the bytes into the given type but go through some efforts to return useful error messages when the JSON is invalid...
func WalkResources ¶
func WrapText ¶
WrapText wraps the provided text string to the given column limit, returning the wrapped string and the number of lines it became. indent gives the amount to indent wrapped lines. By default, lines that start with a space are assumed to be preformatted and are not wrapped; providing a true value for wrapAll overrides that behavior and causes them to be wrapped as well.
Types ¶
type AtomicBool ¶
AtomicBool is a simple wrapper around atomic.Bool that adds support for JSON marshaling/unmarshaling.
func (AtomicBool) MarshalJSON ¶
func (a AtomicBool) MarshalJSON() ([]byte, error)
func (*AtomicBool) UnmarshalJSON ¶
func (a *AtomicBool) UnmarshalJSON(data []byte) error
type CompressedConn ¶
func MakeCompressedConn ¶
func MakeCompressedConn(c net.Conn) (*CompressedConn, error)
func (*CompressedConn) Close ¶
func (c *CompressedConn) Close() error
type ErrorLogger ¶
type ErrorLogger struct {
// contains filtered or unexported fields
}
ErrorLogger is a small utility class used to log errors when validating the parsed JSON scenarios. It tracks context about what is currently being validated and accumulates multiple errors, making it possible to log errors while still continuing validation.
func (*ErrorLogger) CheckDepth ¶ added in v0.11.7
func (e *ErrorLogger) CheckDepth(d int)
func (*ErrorLogger) CurrentDepth ¶ added in v0.11.7
func (e *ErrorLogger) CurrentDepth() int
func (*ErrorLogger) Error ¶
func (e *ErrorLogger) Error(err error)
func (*ErrorLogger) ErrorString ¶
func (e *ErrorLogger) ErrorString(s string, args ...interface{})
func (*ErrorLogger) HaveErrors ¶
func (e *ErrorLogger) HaveErrors() bool
func (*ErrorLogger) Pop ¶
func (e *ErrorLogger) Pop()
func (*ErrorLogger) PrintErrors ¶
func (e *ErrorLogger) PrintErrors(lg *log.Logger)
func (*ErrorLogger) Push ¶
func (e *ErrorLogger) Push(s string)
func (*ErrorLogger) String ¶
func (e *ErrorLogger) String() string
type JSONChecker ¶ added in v0.11.5
type JSONChecker interface {
CheckJSON(json interface{}) bool
}
JSONChecker is an interface that allows types that implement custom JSON unmarshalers to check whether raw unmarshled JSON types are compatible with their underlying type.
type LoggingClientCodec ¶
type LoggingClientCodec struct {
rpc.ClientCodec
// contains filtered or unexported fields
}
func MakeLoggingClientCodec ¶
func MakeLoggingClientCodec(label string, c rpc.ClientCodec, lg *log.Logger) *LoggingClientCodec
func (*LoggingClientCodec) ReadResponseHeader ¶
func (c *LoggingClientCodec) ReadResponseHeader(r *rpc.Response) error
func (*LoggingClientCodec) WriteRequest ¶
func (c *LoggingClientCodec) WriteRequest(r *rpc.Request, v any) error
type LoggingConn ¶
func MakeLoggingConn ¶
func MakeLoggingConn(c net.Conn, lg *log.Logger) *LoggingConn
type LoggingMutex ¶
func (*LoggingMutex) Lock ¶
func (l *LoggingMutex) Lock(lg *log.Logger)
func (*LoggingMutex) LogValue ¶
func (l *LoggingMutex) LogValue() slog.Value
func (*LoggingMutex) Unlock ¶
func (l *LoggingMutex) Unlock(lg *log.Logger)
type LoggingServerCodec ¶
type LoggingServerCodec struct {
rpc.ServerCodec
// contains filtered or unexported fields
}
func MakeLoggingServerCodec ¶
func MakeLoggingServerCodec(label string, c rpc.ServerCodec, lg *log.Logger) *LoggingServerCodec
func (*LoggingServerCodec) ReadRequestHeader ¶
func (c *LoggingServerCodec) ReadRequestHeader(r *rpc.Request) error
func (*LoggingServerCodec) WriteResponse ¶
func (c *LoggingServerCodec) WriteResponse(r *rpc.Response, body any) error
type ObjectArena ¶ added in v0.11.10
type ObjectArena[T any] struct { // contains filtered or unexported fields }
func (*ObjectArena[T]) AllocClear ¶ added in v0.11.10
func (a *ObjectArena[T]) AllocClear() *T
func (*ObjectArena[T]) Cap ¶ added in v0.11.10
func (a *ObjectArena[T]) Cap() int
func (*ObjectArena[T]) Reset ¶ added in v0.11.10
func (a *ObjectArena[T]) Reset()
type OneOf ¶ added in v0.11.5
type OneOf[A, B any] struct { A *A B *B }
func (OneOf[A, B]) MarshalJSON ¶ added in v0.11.5
func (*OneOf[A, B]) UnmarshalJSON ¶ added in v0.11.5
type OrderedMap ¶ added in v0.11.5
type OrderedMap struct {
orderedmap.OrderedMap
}
func (*OrderedMap) CheckJSON ¶ added in v0.11.5
func (o *OrderedMap) CheckJSON(json interface{}) bool
type PendingCall ¶
type PendingCall struct {
Call *rpc.Call
IssueTime time.Time
OnSuccess func(any)
OnErr func(error)
}
func (*PendingCall) CheckFinished ¶
func (p *PendingCall) CheckFinished() bool
type Profiler ¶
type Profiler struct {
// contains filtered or unexported fields
}
func CreateProfiler ¶
type ResourceReadCloser ¶ added in v0.11.8
Unfortunately, unlike io.ReadCloser, the zstd Decoder's Close() method doesn't return an error, so we need to make our own custom ReadCloser interface.
func LoadResource ¶
func LoadResource(path string) ResourceReadCloser
LoadResource provides a ResourceReadCloser to access the specified file from the resources directory; if it's zstd compressed, the Reader will handle decompression transparently. It panics if the file is not found since missing resources are pretty much impossible to recover from.
type RingBuffer ¶
type RingBuffer[V any] struct { // contains filtered or unexported fields }
RingBuffer represents an array of no more than a given maximum number of items. Once it has filled, old items are discarded to make way for new ones.
func NewRingBuffer ¶
func NewRingBuffer[V any](capacity int) *RingBuffer[V]
func (*RingBuffer[V]) Add ¶
func (r *RingBuffer[V]) Add(values ...V)
Add adds all of the provided values to the ring buffer.
func (*RingBuffer[V]) Get ¶
func (r *RingBuffer[V]) Get(i int) V
Get returns the specified element of the ring buffer where the index i is between 0 and Size()-1 and 0 is the oldest element in the buffer.
func (*RingBuffer[V]) Size ¶
func (r *RingBuffer[V]) Size() int
Size returns the total number of items stored in the ring buffer.
type SingleOrArray ¶ added in v0.11.5
type SingleOrArray[V any] []V
SingleOrArray makes it possible to have an object in a JSON file that may be initialized with either a single value or an array of values. In either case, the object's value is represented by a slice of the underlying type.
func (*SingleOrArray[V]) CheckJSON ¶ added in v0.11.5
func (s *SingleOrArray[V]) CheckJSON(json interface{}) bool
func (*SingleOrArray[V]) UnmarshalJSON ¶ added in v0.11.5
func (s *SingleOrArray[V]) UnmarshalJSON(b []byte) error
type TransientMap ¶
type TransientMap[K comparable, V any] struct { // contains filtered or unexported fields }
TransientMap represents a set of objects with a built-in expiry time in the future; after an item's time passes, it is automatically removed from the set.
func NewTransientMap ¶
func NewTransientMap[K comparable, V any]() *TransientMap[K, V]
func (*TransientMap[K, V]) Add ¶
func (t *TransientMap[K, V]) Add(key K, value V, d time.Duration)
Add adds a given value to the set; it will no longer be there after the specified duration has passed.
func (*TransientMap[K, V]) Delete ¶
func (t *TransientMap[K, V]) Delete(key K)
Delete deletes the item in the map with the given key, if present.
func (*TransientMap[K, V]) Get ¶
func (t *TransientMap[K, V]) Get(key K) (V, bool)
Get looks up the given key in the map and returns its value and a Boolean that indicates whether it was found.