pattern

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pattern provides several patterns

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextKeyAnnotation added in v0.13.0

func ContextKeyAnnotation(contextKey any) cli.Action

func IDAnnotation added in v0.13.0

func IDAnnotation[T any](id T) cli.Action

IDAnnotation provides an action which annotates a flag or arg with the identity id. The annotation is placed early and only to flags and args directly defined by the package.

func IdFlag added in v0.13.0

func IdFlag[T any](id T, uses cli.Action) *cli.Flag

IdFlag creates a flag which uses the given action and carries the identity annotation id.

func LookupContextKey added in v0.13.0

func LookupContextKey(target any) (any, bool)

func LookupID added in v0.13.0

func LookupID[T any](target any) (T, bool)

LookupID gets the identity annotation of a flag or arg, if present.

func Unmarshal added in v0.13.0

func Unmarshal[T ~int, Index uint8 | uint16](id *T, data []byte, names string, index []Index) error

Unmarshal parses as a text unmarshaler

Types

type Cacheable

type Cacheable[T comparable] struct {
	// contains filtered or unexported fields
}

Cacheable provides a value that can be set or calculated from a factory. Aside from this, it accumulates and applies middleware using a common function signature

func (*Cacheable[T]) AddMiddleware

func (c *Cacheable[T]) AddMiddleware(values ...func(context.Context, T) T)

AddMiddleware adds a middleware function that will be applied with the result is calculated

func (*Cacheable[T]) Discrete

func (c *Cacheable[T]) Discrete() T

Discrete the discrete value to use as the basis of the result

func (*Cacheable[T]) New

func (c *Cacheable[T]) New(ctx context.Context) (T, error)

New creates the value, either from the discrete value or the factory and applies the middleware. The result is cached, and if an error is generated it is returned on each of the subsequent calls.

func (*Cacheable[T]) SetDiscrete

func (c *Cacheable[T]) SetDiscrete(value T)

SetDiscrete sets a discrete value to use as the basis of the result

func (*Cacheable[T]) SetFactory

func (c *Cacheable[T]) SetFactory(value func(context.Context) (T, error))

SetFactory sets the factory that is used to create the value

Jump to

Keyboard shortcuts

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