Help us shape the future of Go! Take the 2026 Go Developer Survey

resourceexec

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package resourceexec shares a resource request's processing deadline and pure wire sizing with module adapters, without exposing SDK types in the root API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONSize

func JSONSize(response Response) (int, error)

JSONSize measures the exact shared representation; encoding/json escapes text and base64-encodes blob data, including intentional empty variants.

Types

type Item

type Item struct {
	URI      string                     `json:"uri"`
	MIMEType string                     `json:"mimeType,omitempty"`
	Text     *string                    `json:"text,omitempty"`
	Blob     *[]byte                    `json:"blob,omitempty"`
	Metadata map[string]json.RawMessage `json:"_meta,omitempty"`
}

Item is the fixed resource content representation. Pointers preserve empty text/blob variants; private authorization data has no field in this type.

type Response

type Response struct {
	Contents []Item                     `json:"contents"`
	Metadata map[string]json.RawMessage `json:"_meta,omitempty"`
}

Response is the shared contents/report representation before JSON-RPC framing.

type Scope

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

Scope belongs to exactly one read request and its adapter conversion/preflight. The adapter owns Close; a direct root read creates and closes its own scope.

func FromContext

func FromContext(ctx context.Context) *Scope

FromContext returns a supplied adapter scope, if present.

func New

func New(ctx context.Context, size Sizer) *Scope

New starts elapsed processing time at adapter entry, before root execution. A nil sizing callback selects the concrete JSON representation above.

func (*Scope) Bind

func (s *Scope) Bind() context.Context

Bind associates the scope with the request passed to Resources.Read.

func (*Scope) Close

func (s *Scope) Close()

Close ends the request. Root execution never closes an adapter-owned scope.

func (*Scope) Context

func (s *Scope) Context() context.Context

Context keeps the effective deadline available through adapter preflight.

func (*Scope) Size

func (s *Scope) Size(response Response) (size int, err error)

Size contains callback panics and checks cancellation before and after sizing.

func (*Scope) Start

func (s *Scope) Start(ctx context.Context, timeout time.Duration) (context.Context, error)

Start applies the root's configured deadline from the original entry time. The supplied context preserves any stricter host deadline or cancellation.

type Sizer

type Sizer func(Response) (int, error)

Sizer must be pure, nonnegative and conservative. A single-item response size must bound that item's contribution to an aggregate response. Report responses include their own metadata, warning and container overhead. The final callback checks the assembled response; the adapter reserves its separate wire framing.

Jump to

Keyboard shortcuts

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