Documentation
¶
Index ¶
- type Resource
- type ResourceInstance
- func (r *ResourceInstance) Apply(ctx context.Context, v any) error
- func (r *ResourceInstance) HandlerFunc() http.HandlerFunc
- func (r *ResourceInstance) HandlerMiddleware() bool
- func (r *ResourceInstance) HandlerPath() string
- func (r *ResourceInstance) OnStateChange(source schema.ResourceInstance)
- func (r *ResourceInstance) OnStateRemove(source schema.ResourceInstance)
- func (r *ResourceInstance) Read(ctx context.Context) (schema.State, error)
- func (r *ResourceInstance) Spec() *openapi.PathItem
- func (r *ResourceInstance) Validate(ctx context.Context, state schema.State, resolve schema.Resolver) (any, error)
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 ¶
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.
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.