resource

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource struct {
	Middleware bool     `name:"middleware" help:"Whether the router middleware chain wraps this handler" default:"true"`
	Endpoints  []string `name:"endpoints" readonly:"" help:"Full URL endpoints for this handler"`
	// contains filtered or unexported fields
}

Resource describes an HTTP handler resource type. Each resource type is created via NewResource with a unique name, a hard-coded path, the handler function, and an optional OpenAPI spec. The handler is passive: its [Apply] simply stores the configuration. The router pulls the handler via the server.HTTPHandler interface during its own Apply.

func NewResource

func NewResource(name, path string, fn http.HandlerFunc, spec *openapi.PathItem) Resource

NewResource creates a handler resource type with the given unique name, path pattern (relative to the router prefix, e.g. "resource/{id}"), handler function, and optional OpenAPI path-item spec.

func (Resource) Name

func (r Resource) Name() string

func (Resource) New

func (r Resource) New(name string) (schema.ResourceInstance, error)

func (Resource) Schema

func (r Resource) Schema() []schema.Attribute

type ResourceInstance

type ResourceInstance struct {
	provider.ResourceInstance[Resource]
	// contains filtered or unexported fields
}

ResourceInstance is a live instance of an HTTP handler resource.

func (*ResourceInstance) Apply

func (r *ResourceInstance) Apply(ctx context.Context, v any) error

Apply stores the configuration. The actual route registration is performed by the router during its own Apply.

func (*ResourceInstance) HandlerFunc

func (r *ResourceInstance) HandlerFunc() http.HandlerFunc

HandlerFunc returns the captured HTTP handler function.

func (*ResourceInstance) HandlerMiddleware

func (r *ResourceInstance) HandlerMiddleware() bool

HandlerMiddleware reports whether middleware should wrap this handler.

func (*ResourceInstance) HandlerPath

func (r *ResourceInstance) HandlerPath() string

HandlerPath returns the route path relative to the router prefix.

func (*ResourceInstance) OnStateChange

func (r *ResourceInstance) OnStateChange(source schema.ResourceInstance)

OnStateChange is called by the observer system when an instance that references this handler has its state changed. If the source is an httprouter, the reference is stored so [Read] can compute the endpoints dynamically. Multiple routers can reference the same handler, so they are stored in a map keyed by instance name.

func (*ResourceInstance) OnStateRemove

func (r *ResourceInstance) OnStateRemove(source schema.ResourceInstance)

OnStateRemove is called by the observer system when an instance that references this handler is being destroyed. If the source is an httprouter, its reference is removed.

func (*ResourceInstance) Read

Read returns the live state of the handler, computing the endpoints dynamically from all attached routers' current state.

func (*ResourceInstance) Spec

func (r *ResourceInstance) Spec() *openapi.PathItem

HandlerSpec returns the OpenAPI path-item for this handler, or nil.

func (*ResourceInstance) Validate

func (r *ResourceInstance) Validate(ctx context.Context, state schema.State, resolve schema.Resolver) (any, error)

Validate decodes the incoming state, resolves references, and returns the validated *Resource configuration for use by Plan and Apply.

Jump to

Keyboard shortcuts

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