httputil

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySecurityHeaders

func ApplySecurityHeaders(h http.Header)

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

func GetRequestID(ctx context.Context) string

GetRequestID returns the request ID from context, if present.

func JSON

func JSON(w http.ResponseWriter, r *http.Request, code int, data any)

JSON writes a success response with the standard envelope.

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

func JSONMessage(w http.ResponseWriter, r *http.Request, code int, message string, data any)

JSONMessage writes a success response with a message and optional data.

func RequestID

func RequestID() func(http.Handler) http.Handler

RequestID returns a middleware that ensures every request has a request ID.

If the client provides X-Request-ID, it is used (truncated to 128 chars). Otherwise a new UUID is generated. The ID is attached to the request context and echoed in the response header.

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware(next http.Handler) http.Handler

SecurityHeadersMiddleware applies security headers to all responses.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL