common

package
v0.0.0-...-f98e9bb Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

JSON Pointer utilities see: https://datatracker.ietf.org/doc/html/rfc6901

This implementation does not strive to be a perfect implementation of RFC6901. Is is only good enough for the needs of uniond.

Index

Constants

View Source
const (
	UlidByteSize   = 16
	UlidStringSize = 26
)
View Source
const (
	DEFAULT_SELF_SIGNED_CERT_LIFETIME = 365 * 24 * time.Hour
)

Variables

View Source
var (
	ErrUnknown      = errors.New("unknown")
	ErrNotFound     = errors.New("not found")
	ErrConflict     = errors.New("conflict")
	ErrBadInput     = errors.New("bad input")
	ErrNotAllowed   = errors.New("not allowed")
	ErrInvalidState = errors.New("invalid state")
)

Functions

func AssertDirectory

func AssertDirectory(mode fs.FileMode, path string)

func AssertFile

func AssertFile(filePath string) *os.File

func CloseAll

func CloseAll(ctx context.Context, closers ...*CloseHook) []error

func ContextValueAs

func ContextValueAs[A any](ctx context.Context, key any) (*A, error)

func ExecCommand

func ExecCommand(cmd *Command, argv []string) error

Top level entry for cli applications

Execute a command with the given command line arguments.

func ExecCommandContext

func ExecCommandContext(ctx SignalContext, cmd *Command, argv []string) error

Top level entry for cli applications

Execute a command with the given command line arguments and the given context.

func GeneratePassword

func GeneratePassword() string

func GetFunctionName

func GetFunctionName(function any) string

func GroupBy

func GroupBy[A any](slice []A, toKey func(A) string) map[string][]A

func HashPassword

func HashPassword(password string) ([]byte, error)

func LogServiceInit

func LogServiceInit()

func Merge

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

func NewCert

func NewCert(key *ecdsa.PrivateKey) (cert tls.Certificate, signingKey *ecdsa.PrivateKey, signingKeyPem []byte, certPem []byte, err error)

func NewSelfSignedCertificate

func NewSelfSignedCertificate(key *ecdsa.PrivateKey) (*tls.Certificate, *ecdsa.PrivateKey, error)

func Reduce

func Reduce[A any, B any](
	slice []A,
	combine func(accumulator B, next A) B,
) B

func Run

func Run(routine any, modules ...ModuleProvider) (runtimeErr error, closeErrs []error)

func VerifyPassword

func VerifyPassword(password string, hash []byte) error

Types

type AnySlice

type AnySlice []any

type CloseHook

type CloseHook struct {
	// contains filtered or unexported fields
}

type Closer

type Closer struct {
	dig.Out

	Hook *CloseHook `group:"closers"`
}

func NilCloser

func NilCloser() Closer

func OnClose

func OnClose(order int, name string, close func(context.Context) error) Closer

type Closers

type Closers struct {
	dig.In

	Closers []*CloseHook `group:"closers"`
}

type Command

type Command struct {
	Name        string
	Short       string
	Long        string
	Flags       func(fs *flag.FlagSet)
	Run         func(ctx SignalContext) error
	SubCommands []*Command
	// contains filtered or unexported fields
}

func (*Command) Help

func (command *Command) Help() string

The commands help text string

func (*Command) SetParent

func (cmd *Command) SetParent(parent *Command)

used to back-link commands when constructing the command tree

type ContextGetters

type ContextGetters struct {
	dig.In

	ContextValues []ContextValue `group:"contextValues"`
}

type ContextValue

type ContextValue func(ctx context.Context) (key any, value any)

type ContextValues

type ContextValues struct {
	dig.Out

	ContextValues []ContextValue `group:"contextValues,flatten"`
}

type Element

type Element[Value any] struct {
	// contains filtered or unexported fields
}

type Equals

type Equals[A any] interface {
	Equals(other A) bool
}

type ErrorOr

type ErrorOr[Value any] struct {
	Value Value
	Error error
}

func (*ErrorOr[Value]) IsError

func (erroror *ErrorOr[Value]) IsError() bool

type Hashable

type Hashable interface {
	Hash() string
}

type InitHook

type InitHook struct {
	// contains filtered or unexported fields
}

type Initializer

type Initializer struct {
	dig.Out

	Hook *InitHook `group:"initializers"`
}

func NilInit

func NilInit() Initializer

func OnInit

func OnInit(order int, name string, init func(context.Context) error) Initializer

type Initializers

type Initializers struct {
	dig.In

	Initializers []*InitHook `group:"initializers"`
}

type List

type List[Value any] struct {
	// contains filtered or unexported fields
}

func NewList

func NewList[Value any]() *List[Value]

func (*List[Value]) Length

func (list *List[Value]) Length() uint

func (*List[Value]) PutHead

func (list *List[Value]) PutHead(value Value) *List[Value]

func (*List[Value]) PutTail

func (list *List[Value]) PutTail(value Value) *List[Value]

func (*List[Value]) Values

func (list *List[Value]) Values() []Value

type M

type M map[string]any

func (M) As

func (m M) As(receiver any) ([]byte, error)

func (M) Error

func (m M) Error() string

func (*M) InsertValueAt

func (m *M) InsertValueAt(jsonPointer string, value any) error

type Module

type Module interface {
	Sub(provider ModuleProvider)
	Public(service any)
	Private(service any)
	Run(runtime any) (runtimeErr error, closeErrs []error)
	Init([]*InitHook) []error
	Finalize([]*CloseHook) []error
	// contains filtered or unexported methods
}

func LoadModules

func LoadModules(submodules ...ModuleProvider) Module

type ModuleProvider

type ModuleProvider func(Module)

type Set

type Set[A comparable] interface {
	Has(a A) bool
	Add(a A)
	AddAll(a ...A)
	Remove(a A)
	Count() int
	Values() []A
}

func NewSet

func NewSet[A comparable]() Set[A]

type SignalContext

type SignalContext interface {
	context.Context

	// Restart() <-chan time.Duration
	Cancel()
}

func NewSignalContext

func NewSignalContext() SignalContext

type StringStringer

type StringStringer string

func (StringStringer) String

func (s StringStringer) String() string

type Table

type Table[Record any] struct {
	Title   string
	Columns []string
	Records []Record
	ToRow   func(record Record) []any
}

func (*Table[Record]) AddRecords

func (table *Table[Record]) AddRecords(records ...Record)

func (*Table[Record]) Print

func (table *Table[Record]) Print()

type Ulid

type Ulid struct {
	// contains filtered or unexported fields
}

func MustUlidFromString

func MustUlidFromString(encoded string) *Ulid

func NewMonotonicUlid

func NewMonotonicUlid() *Ulid

func NewUlid

func NewUlid() *Ulid

func UlidFromBytes

func UlidFromBytes(bytes []byte) (*Ulid, error)

func UlidFromString

func UlidFromString(encoded string) (*Ulid, error)

func UlidFromTime

func UlidFromTime(time time.Time) *Ulid

func (*Ulid) BitString

func (ulid *Ulid) BitString() string

func (*Ulid) Bytes

func (ulid *Ulid) Bytes() []byte

func (*Ulid) EntropyBytes

func (ulid *Ulid) EntropyBytes() []byte

func (*Ulid) Equals

func (ulid *Ulid) Equals(other *Ulid) bool

func (*Ulid) MarshalJSON

func (ulid *Ulid) MarshalJSON() ([]byte, error)

func (*Ulid) String

func (ulid *Ulid) String() string

func (*Ulid) Time

func (ulid *Ulid) Time() *time.Time

func (*Ulid) TimeBytes

func (ulid *Ulid) TimeBytes() []byte

func (*Ulid) UnmarshalJSON

func (ulid *Ulid) UnmarshalJSON(data []byte) error

type VirtualFS

type VirtualFS interface {
	ReadDir(name string) ([]fs.DirEntry, error)
	ReadFile(name string) ([]byte, error)
}

Directories

Path Synopsis
This file implements the CBOR specification see: https://www.rfc-editor.org/rfc/rfc8949.html
This file implements the CBOR specification see: https://www.rfc-editor.org/rfc/rfc8949.html

Jump to

Keyboard shortcuts

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