resource

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 4 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContextEntry

func AddContextEntry[T any](initializer func(context.Context) (T, error))

AddContextEntry registers a new context entry for the given type T. Only one initializer may be present per type. Only the exact type T is registered, not any compatible interfaces.

It is unsafe to call this function concurrently with itself, or with any functions/methods that create or use a Context. In general, this should only be called during app initialization.

func ContextValue

func ContextValue[T any](ctx context.Context) T

ContextValue retrieves a value of type T from the context, which must have been registered with AddContextEntry. If no value or initializer for the type is found, it will panic. If an initializer is found but not a value, it will also panic.

func DryRun

func DryRun(ctx context.Context) bool

func IsAnti

func IsAnti(r Resource) bool

func Waiter added in v0.6.0

func Waiter(name string, ready func(context.Context) (bool, error)) *waitResource

Waiter creates a resource that blocks during start until the provided ready function passes. That function will also provide the implementation of Ready. Stop is a no-op.

TODO: allow customizing the poll interval

Types

type ContainerResource

type ContainerResource interface {
	Resource
	ContainerImages(context.Context) ([]string, error)
}

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context, opts ...ContextOption) (*Context, error)

NewContext creates a new Context with the given parent context and options.

All context entries registered with AddContextEntry will be initialized proactively, and if any fail this function will return an error.

func NewEmptyContext

func NewEmptyContext(ctx context.Context, opts ...ContextOption) *Context

NewEmptyContext creates a new Context with the given parent context and options, but does not initialize any context entries. If requested, they will be initialized on demand, but if they fail in that case, it will panic.

func (*Context) Value

func (ctx *Context) Value(key any) any

type ContextOption

type ContextOption func(*Context)

func WithDryRun

func WithDryRun() ContextOption

type Resource

type Resource interface {
	ID() string
	Start(context.Context) error
	Stop(context.Context) error
	Ready(context.Context) (bool, error) // TODO: provide not-ready details
}

func Anti

func Anti(inner Resource) Resource

Jump to

Keyboard shortcuts

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