utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Error = errorFlag("utils: error")
)

Variables

This section is empty.

Functions

func NewError

func NewError(skip int, flag error, msg string, args ...any) error

NewError returns a RaisedErr{} that contains file & line of where it was called.

skip allows controlling Caller frame resolution, if you are calling NewError directly set skip to 0, if you are calling NewError from an intermediary newError function set skip to 1...

func RegistryEntries

func RegistryEntries[T any](registry *Registry[T]) map[string]T

RegistryEntries returns a copy of the data in the registry.

func RegistryGet

func RegistryGet[T any](registry *Registry[T], name string) (T, bool)

RegistryGet returns the value referenced by name and a bool indicating if this value exists in the Registry.

func RegistrySet

func RegistrySet[T any](registry *Registry[T], name string, value T) error

RegistrySet adds a new entry to the Registry. It errors if name is already in use.

func WrapError

func WrapError(cause error, skip int, flag error, msg string, args ...any) error

WrapError returns a RaisedErr{} that contains file & line of where it was called. If cause is nil, WrapError returns nil.

skip allows controlling Caller frame resolution, if you are calling NewError directly set skip to 0, if you are calling NewError from an intermediary newError function set skip to 1...

Types

type Bitset

type Bitset []byte

Bitset provides a bit array built on top of a byte slice. Each byte in the underlying slice encodes 8 bits.

func NewBitset

func NewBitset(bits []bool) Bitset

NewBitset returns a Bitset that "compress" the bits argument.

func (Bitset) ClearBit

func (self Bitset) ClearBit(pos int) error

ClearBit set the bit indexed by pos to 0. It errors if pos is not a valid index in the Bitset.

func (Bitset) GetBit

func (self Bitset) GetBit(pos int) (bool, error)

GetBit returns the bit indexed by pos as a bool. It errors if pos is not a valid index

func (Bitset) SetBit

func (self Bitset) SetBit(pos int) error

SetBit set the bit indexed by pos to 1. It errors if pos is not a valid index in the Bitset.

type HexBinary

type HexBinary []byte

func (HexBinary) MarshalText

func (self HexBinary) MarshalText() ([]byte, error)

func (*HexBinary) UnmarshalText

func (self *HexBinary) UnmarshalText(text []byte) error

type RaisedErr

type RaisedErr struct {
	// Flag allows grouping related errors.
	Flag error

	// Cause is the error that caused the RaisedErr{}.
	Cause error

	// Msg describes what happened.
	Msg string

	// Filename is the source file that contains the code that emitted the error.
	Filename string

	// Line is the location in the source file of the code that emitted the error.
	Line int
}

RaisedErr is an error type that tracks error occurence location. All errors returned by KerPass code base functions are RaisedError instances.

Each package may define a private flag error type and a set of **constants** errors having such types. Those flags can be assigned to returned RaisedError to simplify error checking using golang errors.Is.

func (RaisedErr) Error

func (self RaisedErr) Error() string

Error implements the error interface.

func (RaisedErr) Unwrap

func (self RaisedErr) Unwrap() []error

Unwrap returns a slice that contains the causes of the RaisedErr.

type Registry

type Registry[T any] struct {
	// contains filtered or unexported fields
}

Registry holds an inner map[string]T with a mutex to protect accesses.

func NewRegistry

func NewRegistry[T any]() *Registry[T]

NewRegistry returns a Registry[T] pointer.

Jump to

Keyboard shortcuts

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