op

package
v0.0.1-alpha.30 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package op defines the typed operation dispatcher used by Overcast's Smithy-aligned services.

An Operation is a single AWS API method (e.g. SQS:SendMessage) wired to a typed Go function. The dispatcher decodes the request via the active Codec into the operation's input struct, invokes the function, then writes the typed output back through the same codec.

Generics make this allocation-free at the call site: Typed[In, Out] is monomorphised per operation at compile time, so there is no reflection on the request hot path. See docs/plans/smithy.md §9.2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation interface {
	// Name is the AWS operation name (e.g. "SendMessage", "GetItem").
	// Used for diagnostics, logging, and routing.
	Name() string

	// Invoke runs the operation: decode the request via c, call the
	// typed function, then write the response (or error) via c.
	//
	// Invoke MUST NOT return — all responses, including errors, are
	// written to w. This matches http.HandlerFunc semantics and lets
	// the caller treat operations interchangeably with raw handlers
	// during the migration.
	Invoke(w http.ResponseWriter, r *http.Request, c codec.Codec)
}

Operation is a runtime-dispatchable, codec-agnostic AWS operation.

Implementations are produced by NewTyped and stored in per-service operation registries keyed by the AWS operation name (e.g. "SendMessage"). The router or service handler resolves the codec, looks up the operation, and calls Invoke.

func NewRaw

func NewRaw(name string, fn http.HandlerFunc) Operation

NewRaw adapts an existing http.HandlerFunc into an Operation.

Raw operations are a migration escape hatch for handlers that still own their request decoding, response encoding, or custom headers. The codec argument is intentionally ignored.

func NewTyped

func NewTyped[In any, Out any](
	name string,
	fn func(ctx context.Context, in *In) (*Out, *protocol.AWSError),
) Operation

NewTyped builds an Operation from a typed function.

name is the AWS operation name. fn is the business logic; it must not write to the http.ResponseWriter directly — that's the dispatcher's job. fn may return (nil, nil) for void operations, which produces an empty success response.

func NewTypedAny

func NewTypedAny[In any](
	name string,
	fn func(ctx context.Context, in *In) (any, *protocol.AWSError),
) Operation

NewTypedAny builds an Operation whose success response shape can vary.

Prefer NewTyped when an operation has a single concrete output shape. NewTypedAny is for Smithy operations like DynamoDB Scan/Query where one request flag selects between distinct wire shapes that must stay byte-stable.

type Raw

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

func (*Raw) Invoke

func (r *Raw) Invoke(w http.ResponseWriter, req *http.Request, _ codec.Codec)

func (*Raw) Name

func (r *Raw) Name() string

type Typed

type Typed[In any, Out any] struct {
	// contains filtered or unexported fields
}

Typed is the generic implementation of Operation for a function with a typed input and typed output.

In and Out are the operation's request and response struct types (typically pointers to structs). Fn receives a context for cancellation/deadlines and the decoded input; it returns the typed output and an optional *protocol.AWSError. A non-nil error is rendered through the codec's WriteError; a nil error renders Out through WriteResponse with HTTP 200.

Typed is an unexported struct returned through the Operation interface to keep the surface narrow; construct one with NewTyped.

func (*Typed[In, Out]) Invoke

func (t *Typed[In, Out]) Invoke(w http.ResponseWriter, r *http.Request, c codec.Codec)

Invoke implements Operation. The implementation is deliberately tiny to keep the hot path inlinable: one decode, one call, one write.

func (*Typed[In, Out]) Name

func (t *Typed[In, Out]) Name() string

Name implements Operation.

type TypedAny

type TypedAny[In any] struct {
	// contains filtered or unexported fields
}

func (*TypedAny[In]) Invoke

func (t *TypedAny[In]) Invoke(w http.ResponseWriter, r *http.Request, c codec.Codec)

func (*TypedAny[In]) Name

func (t *TypedAny[In]) Name() string

Jump to

Keyboard shortcuts

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