envelope

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package envelope provides the common execution envelope for storage operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[P shared.Param, R any](
	ctx context.Context,
	config Config[P],
	body func(context.Context, *P) (Result[R], error),
) (R, error)

Run executes a storage operation inside its tracing, options, params, hooks, logging, metrics, and error-reporting envelope.

Types

type Config

type Config[P shared.Param] struct {
	Storage storage.IStorage

	Adapter string
	Status  string

	ID       string
	Target   string
	HookData any

	// ResolveTarget, when set, computes the target after params are merged and
	// before the hooks run — inside the span, so a resolution failure is traced
	// like any other. Its result replaces Target for both hooks and is passed to
	// the body.
	//
	// It exists because the adapters differ on this: some have a fixed target,
	// while the SQL adapters derive one from the caller's argument and their own
	// configured default via shared.TargetName. Resolving before Run would move
	// the failure outside the span, and resolving inside body would run the
	// pre-hook too early and hand it an unresolved target. Both are behaviour
	// changes, so the resolution point has to sit here.
	ResolveTarget func() (string, error)

	Param      *P
	Options    []storage.Func[*P]
	NewParams  func() (*P, error)
	RequiresID bool

	SuccessCounter *expvar.Int
	FailureCounter *expvar.Int
}

Config contains the operation-specific inputs to Run.

type Result

type Result[R any] struct {
	Value        R
	PostHookData any
}

Result contains the operation result and the data passed to the post-hook.

type Void

type Void struct{}

Void is the result type for operations that return only an error.

Jump to

Keyboard shortcuts

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