Documentation
¶
Index ¶
- Constants
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, problem ProblemDetailsError)
- func ProblemType(slug string) string
- func ResolveRelativePath(raw, baseDir string) string
- type ByteSize
- type Connection
- type Context
- type ContextOption
- type Duration
- type ErrorHandler
- type Field
- type InvalidParam
- type OpenAPIConfig
- type OpenAPIContact
- type OpenAPILicense
- type OpenAPIServer
- type OpenAPITag
- type Options
- type PoolConfig
- type ProblemDetailsError
- type RequestState
- type Schema
- type Server
- type StepHandler
- type StepResult
Constants ¶
const DefaultErrorTypePrefix = "urn:hclapi:error:"
DefaultErrorTypePrefix is the standard URN namespace prefix for built-in error types.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, problem ProblemDetailsError)
DefaultErrorHandler returns a ProblemDetailsError with default values.
func ProblemType ¶
ProblemType returns a standard URN identifier for a given error slug.
func ResolveRelativePath ¶
ResolveRelativePath resolves a relative file path or file-based DSN against baseDir.
Types ¶
type ByteSize ¶
type ByteSize int64
ByteSize represents a quantity of bytes that can be unmarshaled from text.
const ( B ByteSize = 1 KB ByteSize = 1000 * B KiB ByteSize = 1024 * B MB ByteSize = 1000 * KB MiB ByteSize = 1024 * KiB GB ByteSize = 1000 * MB GiB ByteSize = 1024 * MiB TB ByteSize = 1000 * GB TiB ByteSize = 1024 * GiB )
ByteSize constants represent byte sizes.
func ParseByteSize ¶
ParseByteSize parses human-readable byte strings into a ByteSize.
func (ByteSize) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ByteSize) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Connection ¶
type Connection struct {
Driver string
Name string
URL string
Pool PoolConfig
}
Connection represents a resolved connection configuration with driver metadata and pool limits.
func (Connection) Key ¶
func (c Connection) Key() string
Key returns the unique identifier for the connection pool (e.g. "postgres.main").
func (Connection) Reference ¶
func (c Connection) Reference() string
Reference returns the full HCL reference path (e.g. "connection.postgres.main").
type Context ¶
type Context struct {
Request *RequestState `json:"request"`
Steps map[string]map[string]any `json:"steps"`
TimestampEpoch int64 `json:"timestamp_epoch"`
IngressTime time.Time `json:"-"`
Server Server `json:"-"`
RawRequest *http.Request `json:"-"`
}
Context encapsulates the runtime execution state for a single HTTP request lifecycle.
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request, opts ...ContextOption) (*Context, error)
NewContext parses the HTTP request, enforcing max body size and decoding payloads.
type ContextOption ¶
type ContextOption func(*contextConfig)
ContextOption configures optional behavior during Context creation.
func WithPathParams ¶
func WithPathParams(paramNames []string) ContextOption
WithPathParams configures route parameter names to extract from the request.
func WithServer ¶
func WithServer(server Server) ContextOption
WithServer attaches the resolved server configuration to the request context.
type Duration ¶
Duration wraps a time.Duration with universal text deserialization.
func (Duration) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Duration) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, problem ProblemDetailsError)
ErrorHandler defines the contract for customizing API error serialization.
type Field ¶
type Field struct {
Name string
Type string // "string", "int", "float", "bool", "any", "list(string)", etc.
Required bool
Default any // Evaluated static default or nil
Description string
Enum []any // Evaluated allowed values or nil
Format string // "email", "uuid", "date-time", etc.
Pattern string // Regex pattern or empty
MinLength *int
MaxLength *int
Min *float64
Max *float64
MinItems *int
MaxItems *int
UniqueItems bool
}
Field represents a compiled, type-safe schema field rule.
type InvalidParam ¶
InvalidParam represents a single field validation failure.
type OpenAPIConfig ¶
type OpenAPIConfig struct {
Title string
Version string
Description string
Servers []OpenAPIServer
Tags []OpenAPITag
Contact *OpenAPIContact
License *OpenAPILicense
}
OpenAPIConfig holds global OpenAPI 3.1 document header metadata.
type OpenAPIContact ¶
OpenAPIContact defines API contact details.
type OpenAPILicense ¶
OpenAPILicense defines API licensing information.
type OpenAPIServer ¶
OpenAPIServer defines a target server deployment in the OpenAPI spec.
type OpenAPITag ¶
OpenAPITag defines an operation category tag.
type Options ¶
type Options struct {
// ConfigPath is a file or directory of .hcl definitions.
ConfigPath string
// StrictTyping enforces request schema validation on all endpoints.
StrictTyping bool
// ErrorHandler formats error responses. If nil, RFC 9457 defaults are used.
ErrorHandler ErrorHandler
// Logger receives operational logs. If nil, logging is discarded.
Logger *slog.Logger
}
Options defines the configuration options for the hclapi engine.
type PoolConfig ¶
type PoolConfig struct {
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime Duration
IdleTimeout Duration
Size int
}
PoolConfig defines connection pool sizing and lifecycle settings.
func DefaultPoolConfig ¶
func DefaultPoolConfig() PoolConfig
DefaultPoolConfig returns baseline production connection pool settings.
type ProblemDetailsError ¶
type ProblemDetailsError struct {
Type string `json:"type,omitempty"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Step string `json:"step,omitempty"`
InvalidParams []InvalidParam `json:"invalid_params,omitempty"`
Extensions map[string]any `json:"extensions,omitempty"`
}
ProblemDetailsError represents an RFC 9457 compliant error object.
func (ProblemDetailsError) Error ¶
func (p ProblemDetailsError) Error() string
Error implements the standard error interface.
type RequestState ¶
type RequestState struct {
Method string `json:"method"`
Path map[string]string `json:"path"`
Query map[string]string `json:"query"`
Headers map[string]string `json:"headers"`
Body any `json:"body"`
}
RequestState represents normalized HTTP request metadata extracted at runtime.
type Server ¶
type Server struct {
Host string
Port int
ReadTimeout Duration
WriteTimeout Duration
IdleTimeout Duration
MaxBodySize ByteSize
ErrorBaseURL string // TODO: validate introducing a new block to put stuff like this
OpenAPI OpenAPIConfig
}
Server defines the resolved HTTP server configuration.
func DefaultServer ¶
func DefaultServer() Server
DefaultServer returns baseline production configuration values.
func (Server) ProblemType ¶
ProblemType returns the error URI using ErrorBaseURL or the default URN prefix.
func (Server) WithDefaults ¶
WithDefaults returns a copy of Server with any zero values replaced by baseline defaults.
type StepHandler ¶
StepHandler defines the signature for custom native Go step callbacks.
type StepResult ¶
StepResult represents arbitrary step-specific outputs.