resource

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	OpenAPIPath  = "/openapi.json"
	ResourceType = "httprouter"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource struct {
	Prefix     string                    `name:"prefix" default:"/" help:"URL path prefix for all routes"`
	Origin     string                    `` /* 186-byte string literal not displayed */
	Title      string                    `name:"title" required:"" help:"OpenAPI spec title"`
	Version    string                    `name:"version" required:"" help:"OpenAPI spec version"`
	Endpoints  []string                  `name:"endpoints" readonly:"" help:"Base URLs of the router (one per attached server)"`
	OpenAPI    bool                      `name:"openapi" default:"true" help:"Serve OpenAPI spec at {prefix}/openapi.json"`
	Middleware []schema.ResourceInstance `name:"middleware" help:"Ordered middleware instances to attach to the router"`
	Handlers   []schema.ResourceInstance `name:"handlers" help:"Handler instances to register on the router"`
}

func (Resource) Name

func (Resource) Name() string

func (Resource) New

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

func (Resource) Schema

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

type ResourceInstance

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

func (*ResourceInstance) Apply

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

Apply materialises the resource using the validated configuration. It creates the router, attaches middleware in order, registers handlers, and adds default endpoints (404 and OpenAPI).

func (*ResourceInstance) Destroy

func (r *ResourceInstance) Destroy(_ context.Context) error

Destroy tears down the resource and releases its backing infrastructure. It returns an error if the resource cannot be cleanly removed.

func (*ResourceInstance) OnStateChange

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

OnStateChange is called by the observer system when an instance that references this router has its state changed. If the source implements server.HTTPServer, its spec is stored and the OpenAPI spec's servers list is updated.

func (*ResourceInstance) OnStateRemove

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

OnStateRemove is called by the observer system when an instance that references this router is being destroyed. If the source implements server.HTTPServer, its entry is removed.

func (*ResourceInstance) Read

Read returns the live state of the router, including the endpoints collected from attached servers.

func (*ResourceInstance) ServeHTTP

func (r *ResourceInstance) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP delegates to the underlying router. This allows the resource instance to be used as an http.Handler by the httpserver.

func (*ResourceInstance) Spec

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

Spec returns the OpenAPI specification for this router, or nil if the router has not been initialised yet.

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