Documentation
¶
Index ¶
- Constants
- type Resource
- type ResourceInstance
- func (r *ResourceInstance) Apply(ctx context.Context, v any) error
- func (r *ResourceInstance) Destroy(_ context.Context) error
- func (r *ResourceInstance) OnStateChange(source schema.ResourceInstance)
- func (r *ResourceInstance) OnStateRemove(source schema.ResourceInstance)
- func (r *ResourceInstance) Read(_ context.Context) (schema.State, error)
- func (r *ResourceInstance) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *ResourceInstance) Spec() *openapi.Spec
- func (r *ResourceInstance) Validate(ctx context.Context, state schema.State, resolve schema.Resolver) (any, error)
Constants ¶
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"`
}
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.