Documentation
¶
Overview ¶
Package http adapts Datly runtime execution to HTTP transport.
Index ¶
- Constants
- type APIKey
- type APIKeys
- type AsyncAdmission
- type AsyncInspect
- type AsyncRoute
- type AsyncService
- type CacheInvalidationConfig
- type Config
- type DocumentAccess
- type DocumentExport
- type Handler
- type HandlerInput
- type Meta
- type MetricsConfig
- type OpenAPIConfig
- type WarmupConfig
- type WarmupLifetime
- type WarmupResult
Constants ¶
const DefaultCacheInvalidateURI = "/v1/api/cache/invalidate"
const DefaultCacheWarmURI = "/v1/api/cache/warmup"
const DefaultDocURI = "/v1/api/meta/doc"
const DefaultOpenAPIURI = "/v1/api/meta/openapi"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeys ¶
type APIKeys []APIKey
type AsyncAdmission ¶
type AsyncAdmission interface {
Begin(context.Context) (context.Context, AsyncService, func(), error)
}
AsyncAdmission borrows Manager's already-pinned generation for this HTTP request and tracks preparation, execution and response handling until release.
type AsyncInspect ¶
Result requires a real completed reader and current target query/body/JWT sources. False is status-only and never invokes the reader. SyncFlag may be configured on a result route to explicitly refresh instead of cache-only lookup.
type AsyncRoute ¶
type AsyncRoute struct {
Route spec.RouteRef
MatchKey string
SyncFlag string
// Inspect configures a separate authored route to inspect exact stored IDs.
// Its input contract still verifies any declared JWT before status authorization.
Inspect *AsyncInspect
}
AsyncRoute explicitly enables original default scheduling for an exact public route. Controls name existing canonical input fields, never HTTP parameter locations. No implicit async/sync query flag or arbitrary target is accepted.
type AsyncService ¶
AsyncService is supplied by application.Manager with its generation and owned admission lifetime. It delegates durable work to the existing jobs.Service.
type CacheInvalidationConfig ¶ added in v1.1.0
type CacheInvalidationConfig struct {
Timeout time.Duration
Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error
}
CacheInvalidationConfig enables cache administration independently of warmup. Authorize must grant administrator access to this exact server-selected target.
type Config ¶
type Config struct {
// Metrics opts into diagnostic response headers. Nil disables them.
Metrics *MetricsConfig `json:"Metrics,omitempty" yaml:"Metrics,omitempty"`
Async []AsyncRoute `json:"Async,omitempty" yaml:"Async,omitempty"`
// StaticLocalRoot is an optional caller-owned local filesystem authority.
// Configured ContentURL paths beneath it must be relative and symlink-free.
// Keep it open until all reloads finish. JSON configuration cannot grant it.
StaticLocalRoot *os.Root `json:"-"`
StaticContent []*spec.StaticContent
ContentURL string
APIKeys APIKeys `json:"APIKeys,omitempty" yaml:"APIKeys,omitempty"`
DisableCors bool `json:"DisableCors,omitempty" yaml:"DisableCors,omitempty"`
CORS *spec.CORS `json:"CORS,omitempty" yaml:"CORS,omitempty"`
APIPrefix string `json:"APIPrefix,omitempty" yaml:"APIPrefix,omitempty"`
Meta Meta `json:"Meta,omitempty" yaml:"Meta,omitempty"`
OpenAPI *OpenAPIConfig `json:"OpenAPI,omitempty" yaml:"OpenAPI,omitempty"`
Warmup *WarmupConfig `json:"-" yaml:"-"`
CacheInvalidation *CacheInvalidationConfig `json:"-" yaml:"-"`
// Authorize applies application policy to every resolved component target
// after route/API-key checks and before request binding or execution.
Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error `json:"-" yaml:"-"`
}
Config is the application HTTP policy. A nil CORS policy selects safe noncredentialed defaults; an explicit empty CORS policy remains empty.
type DocumentAccess ¶
type DocumentAccess struct {
APIKeyHeader string `json:"APIKeyHeader" yaml:"APIKeyHeader"`
APIKeyValue string `json:"APIKeyValue" yaml:"APIKeyValue"`
}
func (*DocumentAccess) Authorize ¶
func (p *DocumentAccess) Authorize(request *http.Request) error
Authorize applies the same explicit key policy to documents and configured warmup administration. A nil document policy retains public-document behavior.
func (*DocumentAccess) Validate ¶
func (p *DocumentAccess) Validate() error
type DocumentExport ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func (*Handler) ExportOpenAPI ¶
func (h *Handler) ExportOpenAPI(request openapi.ExportRequest) ([]byte, error)
type HandlerInput ¶
type HandlerInput struct {
Async AsyncAdmission
Runtime *druntime.Runtime
Components []*registry.RegisteredComponent
Logger xlogger.Logger
Version string
}
HandlerInput carries canonical registrations only during HTTP staging. They are consumed to freeze documents, never exposed as a mutable registry.
type Meta ¶
type Meta struct {
// AllowedSubnet retains original RemoteAddr prefix matching (not CIDR parsing).
AllowedSubnet []string `json:"AllowedSubnet,omitempty" yaml:"AllowedSubnet,omitempty"`
OpenApiURI string `json:"OpenApiURI,omitempty" yaml:"OpenApiURI,omitempty"`
DocURI string `json:"DocURI,omitempty" yaml:"DocURI,omitempty"`
CacheWarmURI string `json:"CacheWarmURI,omitempty" yaml:"CacheWarmURI,omitempty"`
CacheInvalidateURI string `json:"CacheInvalidateURI,omitempty" yaml:"CacheInvalidateURI,omitempty"`
}
Meta preserves original Init semantics: empty selects the default URI; a nonempty whitespace value explicitly disables warmup route activation.
type MetricsConfig ¶
type MetricsConfig struct {
AllowSQL bool `json:"AllowSQL,omitempty" yaml:"AllowSQL,omitempty"`
Authorize func(*http.Request) error `json:"-" yaml:"-"`
}
MetricsConfig is operator policy for client-requested diagnostic headers. Configuring it enables SQL-redacted metrics; AllowSQL separately enables SQL and arguments for debug requests. Authorize can further restrict each caller.
type OpenAPIConfig ¶
type OpenAPIConfig struct {
Info openapi3.Info `json:"Info" yaml:"Info"`
AggregateAccess *DocumentAccess `json:"AggregateAccess,omitempty" yaml:"AggregateAccess,omitempty"`
RouteAccess *DocumentAccess `json:"RouteAccess,omitempty" yaml:"RouteAccess,omitempty"`
// StartupExports is consumed by standalone after initial publication, before
// listener admission. Rendering remains owned by Manager.ExportOpenAPI.
StartupExports []DocumentExport `json:"StartupExports,omitempty" yaml:"StartupExports,omitempty"`
}
OpenAPIConfig opts application staging into document generation. Document access is independent of the component security described inside documents. Nil access policies retain original public document-route behavior.
type WarmupConfig ¶
type WarmupConfig struct {
Lifetime *WarmupLifetime
Timeout time.Duration
Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error
// AdminHeaders are the extra request headers available to Authorize. API-key
// and canonical JWT headers are copied automatically; bodies are never retained.
AdminHeaders []string
// Completed receives preparation failures and every dispatched operation outcome,
// even after client cancellation. Callbacks must support concurrent requests.
Completed func(WarmupResult, error)
}
WarmupConfig supplies server lifetime and explicit administration policy. Authorize must authorize this exact target; a successful component JWT alone does not grant cache administration. Lifetime must be server-owned.
type WarmupLifetime ¶
type WarmupLifetime struct {
// contains filtered or unexported fields
}
WarmupLifetime owns admission and completion across any handlers sharing it. It stores no handlers, generations or requests. Application.Manager supplies one instance to all its staged HTTP generations, including pinned generations.
func NewWarmupLifetime ¶
func NewWarmupLifetime(parent context.Context) *WarmupLifetime
func (*WarmupLifetime) Shutdown ¶
func (l *WarmupLifetime) Shutdown(ctx context.Context) error
Shutdown rejects new accepted operations, cancels authorization, preparation and execution, then joins all previously accepted work. Repeated calls can wait again after an earlier caller deadline. Callbacks must honor operation context.