Documentation
¶
Index ¶
- func ApplySecurityHeaders(h http.Header)
- func GetRequestID(ctx context.Context) string
- func JSON(w http.ResponseWriter, r *http.Request, code int, data any)
- func JSONError(w http.ResponseWriter, r *http.Request, httpCode int, errCode string, ...)
- func JSONErrorWithDetails(w http.ResponseWriter, r *http.Request, httpCode int, errCode string, ...)
- func JSONMessage(w http.ResponseWriter, r *http.Request, code int, message string, data any)
- func RequestID() func(http.Handler) http.Handler
- func SecurityHeadersMiddleware(next http.Handler) http.Handler
- type ErrorBody
- type Meta
- type PaginationMeta
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySecurityHeaders ¶
ApplySecurityHeaders sets a minimal set of security headers.
Set ALLOWED_FRAME_ORIGINS to a comma or space-separated list of origins (e.g. "https://kombify.io https://kombify.space" or "https://kombify.io,https://kombify.space") to allow embedding in iframes. When set, X-Frame-Options is replaced with Content-Security-Policy: frame-ancestors to allow embedding in the kombify Cloud portal. Each origin is validated as a proper URL origin to prevent CSP injection.
func GetRequestID ¶
GetRequestID returns the request ID from context, if present.
func JSONError ¶
func JSONError(w http.ResponseWriter, r *http.Request, httpCode int, errCode string, message string)
JSONError writes an error response with the standard envelope.
func JSONErrorWithDetails ¶
func JSONErrorWithDetails(w http.ResponseWriter, r *http.Request, httpCode int, errCode string, message string, details any)
JSONErrorWithDetails writes an error response with additional details.
func JSONMessage ¶
JSONMessage writes a success response with a message and optional data.
Types ¶
type ErrorBody ¶
type ErrorBody struct {
Code string `json:"code"`
Message string `json:"message"`
Details any `json:"details,omitempty"`
}
ErrorBody carries structured error details.
type Meta ¶
type Meta struct {
RequestID string `json:"request_id,omitempty"`
Timestamp string `json:"timestamp"`
}
Meta carries request metadata in the response envelope.
type PaginationMeta ¶
type PaginationMeta struct {
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
PaginationMeta extends data with pagination info for collection endpoints.
type Response ¶
type Response struct {
Status string `json:"status"`
Code int `json:"code"`
Message string `json:"message,omitempty"`
Data any `json:"data,omitempty"`
Meta *Meta `json:"meta,omitempty"`
Error *ErrorBody `json:"error,omitempty"`
}
Response is the standard API response envelope defined in API-FIRST-STANDARD.md.
All kombify API endpoints SHOULD use this envelope for consistency. Exceptions: SSE streams, file downloads, health checks (plain 200 OK).