Documentation
¶
Overview ¶
Package httpx provides runtime debug admin dashboard endpoints for gorp framework.
Package httpx provides OpenAPI 3.0 route introspection and auto-export capabilities.
Package httpx provides HTTP response helpers and error mappings for gorp framework.
Package httpx provides unified HTTP response and documentation helpers for gorp framework.
Index ¶
- Constants
- func DashboardHTML(prefix string) string
- func Error(c JSONResponder, err error)
- func ErrorWithData(c JSONResponder, err error, data any)
- func ErrorWithStatus(c JSONResponder, status int, err error)
- func ExportOpenAPI3JSON(engine *gin.Engine, title, version string) string
- func Fail(c JSONResponder, err error)
- func GinSwaggerHandler(specPath string) gin.HandlerFunc
- func IsProblemJSONEnabled() bool
- func MountDebugDashboard(engine *gin.Engine, container runtimecontract.Container, prefix ...string)
- func OK(c JSONResponder, data any)
- func RegisterAdminDashboard(engine *gin.Engine, container runtimecontract.Container, pathPrefix string, ...)
- func Success(c JSONResponder, data any)
- func SuccessPaginated(c JSONResponder, items any, total int64, page, pageSize int)
- func SuccessWithMessage(c JSONResponder, message string, data any)
- func SuccessWithStatus(c JSONResponder, status int, data any)
- func SwaggerUIHTML(specURL, title string) string
- func UseProblemJSON(enabled bool)
- type AdminDashboardOption
- type AdminDashboardOptions
- type BizError
- func Aborted(reason, msg string) *BizError
- func AlreadyExists(reason, msg string) *BizError
- func Cancelled(reason, msg string) *BizError
- func DataLoss(reason, msg string) *BizError
- func DeadlineExceeded(reason, msg string) *BizError
- func FailedPrecondition(reason, msg string) *BizError
- func Internal(msg string) *BizError
- func InvalidArgument(reason, msg string) *BizError
- func NewBizError(code Code, reason, message string) *BizError
- func NotFound(reason, msg string) *BizError
- func OutOfRange(reason, msg string) *BizError
- func PermissionDenied(reason, msg string) *BizError
- func ResourceExhausted(reason, msg string) *BizError
- func Unauthenticated(reason, msg string) *BizError
- func Unavailable(reason, msg string) *BizError
- func Unimplemented(reason, msg string) *BizError
- func Unknown(reason, msg string) *BizError
- type BusinessError
- type Code
- type JSONResponder
- type OpenAPI3Components
- type OpenAPI3Document
- type OpenAPI3Info
- type OpenAPI3Operation
- type OpenAPI3Parameter
- type OpenAPI3Response
- type OpenAPI3SecurityScheme
- type PaginatedData
- type Problem
- type Response
Constants ¶
const CodeSuccess = CodeOK
CodeSuccess is an alias for CodeOK to maintain compatibility where needed.
Variables ¶
This section is empty.
Functions ¶
func DashboardHTML ¶ added in v0.2.0
DashboardHTML returns the self-contained HTML page for the /debug/gorp Web Console.
func Error ¶
func Error(c JSONResponder, err error)
Error writes an error response, automatically resolving AppError and BizError.
func ErrorWithData ¶
func ErrorWithData(c JSONResponder, err error, data any)
ErrorWithData writes an error response and attaches extra response data.
func ErrorWithStatus ¶
func ErrorWithStatus(c JSONResponder, status int, err error)
ErrorWithStatus writes an error response using a caller-provided HTTP status.
func ExportOpenAPI3JSON ¶ added in v0.2.0
ExportOpenAPI3JSON converts the Gin routes to formatted OpenAPI 3.0 JSON.
func GinSwaggerHandler ¶ added in v0.2.0
func GinSwaggerHandler(specPath string) gin.HandlerFunc
GinSwaggerHandler returns a Gin handler that serves interactive Swagger UI or the spec JSON.
func IsProblemJSONEnabled ¶ added in v0.3.0
func IsProblemJSONEnabled() bool
IsProblemJSONEnabled reports whether RFC 9457 Problem Details is enabled.
func MountDebugDashboard ¶ added in v0.2.0
func MountDebugDashboard(engine *gin.Engine, container runtimecontract.Container, prefix ...string)
MountDebugDashboard attaches the /debug/gorp developer console and JSON API endpoints to Gin.
func RegisterAdminDashboard ¶ added in v0.2.0
func RegisterAdminDashboard(engine *gin.Engine, container runtimecontract.Container, pathPrefix string, opts ...AdminDashboardOption)
RegisterAdminDashboard mounts the /debug/gorp Web Admin Console and REST endpoints onto a Gin engine.
func SuccessPaginated ¶
func SuccessPaginated(c JSONResponder, items any, total int64, page, pageSize int)
SuccessPaginated writes a standard paginated success response.
func SuccessWithMessage ¶
func SuccessWithMessage(c JSONResponder, message string, data any)
SuccessWithMessage writes a success response with a custom message.
func SuccessWithStatus ¶
func SuccessWithStatus(c JSONResponder, status int, data any)
SuccessWithStatus writes a success response with a custom HTTP status.
func SwaggerUIHTML ¶ added in v0.2.0
SwaggerUIHTML returns a lightweight, self-contained HTML string loading Swagger UI CDN.
func UseProblemJSON ¶ added in v0.3.0
func UseProblemJSON(enabled bool)
UseProblemJSON enables or disables RFC 9457 Problem Details (application/problem+json) error responses.
Types ¶
type AdminDashboardOption ¶ added in v0.2.0
type AdminDashboardOption func(*AdminDashboardOptions)
AdminDashboardOption configures AdminDashboardOptions.
func WithAdminToken ¶ added in v0.2.0
func WithAdminToken(token string) AdminDashboardOption
WithAdminToken sets the required bearer or query token to access the debug dashboard.
func WithAllowInProduction ¶ added in v0.2.0
func WithAllowInProduction(allow bool) AdminDashboardOption
WithAllowInProduction explicitly permits access to the dashboard in gin.ReleaseMode.
func WithPathPrefix ¶ added in v0.2.2
func WithPathPrefix(prefix string) AdminDashboardOption
WithPathPrefix sets a custom mount path prefix for the debug dashboard (default: "/debug/gorp").
type AdminDashboardOptions ¶ added in v0.2.0
type AdminDashboardOptions struct {
AdminToken string // If specified, requests must provide Authorization: Bearer <token> or ?token=<token>
AllowInProduction bool // If false, /debug/gorp returns 403 Forbidden in release/production mode (default: false)
PathPrefix string // Mount path prefix (default: "/debug/gorp")
}
AdminDashboardOptions configures security and behavior of the developer console.
func DefaultAdminDashboardOptions ¶ added in v0.2.0
func DefaultAdminDashboardOptions() AdminDashboardOptions
DefaultAdminDashboardOptions returns default production-safe options.
type BizError ¶
type BizError struct {
// contains filtered or unexported fields
}
BizError is the standard business error carrying canonical Code and domain Reason.
func AlreadyExists ¶ added in v0.3.0
func DeadlineExceeded ¶ added in v0.3.0
func FailedPrecondition ¶ added in v0.3.0
func InvalidArgument ¶ added in v0.3.0
Convenient constructors for canonical codes (covers 90%+ business scenarios).
func NewBizError ¶
NewBizError creates a new BizError with constructor-level fail-fast verification.
func OutOfRange ¶ added in v0.3.0
func PermissionDenied ¶ added in v0.3.0
func ResourceExhausted ¶ added in v0.3.0
func Unauthenticated ¶ added in v0.3.0
func Unavailable ¶ added in v0.3.0
func Unimplemented ¶ added in v0.3.0
type BusinessError ¶
BusinessError describes an error carrying canonical Code, Reason, and message semantics.
type Code ¶ added in v0.3.0
type Code int
Code represents canonical semantic status codes aligned with gRPC AIP-193. It determines the HTTP transmission status, while business domain semantics use Reason.
const ( CodeOK Code = 0 CodeCancelled Code = 1 CodeUnknown Code = 2 CodeInvalidArgument Code = 3 // -> 400 CodeDeadlineExceeded Code = 4 // -> 504 CodeNotFound Code = 5 // -> 404 CodeAlreadyExists Code = 6 // -> 409 CodePermissionDenied Code = 7 // -> 403 CodeResourceExhausted Code = 8 // -> 429 CodeFailedPrecondition Code = 9 // -> 400 CodeAborted Code = 10 // -> 409 CodeOutOfRange Code = 11 // -> 400 CodeUnimplemented Code = 12 // -> 501 CodeInternal Code = 13 // -> 500 CodeDataLoss Code = 15 // -> 500 CodeUnauthenticated Code = 16 // -> 401 )
type JSONResponder ¶ added in v0.2.0
JSONResponder represents any context capable of rendering a JSON response, seamlessly supporting both *gin.Context and transportcontract.Context.
type OpenAPI3Components ¶ added in v0.2.0
type OpenAPI3Components struct {
SecuritySchemes map[string]OpenAPI3SecurityScheme `json:"securitySchemes,omitempty"`
}
OpenAPI3Components defines reusable OpenAPI schemas.
type OpenAPI3Document ¶ added in v0.2.0
type OpenAPI3Document struct {
OpenAPI string `json:"openapi"`
Info OpenAPI3Info `json:"info"`
Paths map[string]map[string]OpenAPI3Operation `json:"paths"`
Components *OpenAPI3Components `json:"components,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
}
OpenAPI3Document represents a lightweight OpenAPI 3.0 root document.
func ExportOpenAPI3 ¶ added in v0.2.0
func ExportOpenAPI3(engine *gin.Engine, title, version string) *OpenAPI3Document
ExportOpenAPI3 inspects the Gin engine's routes and auto-generates an OpenAPI 3.0 spec document.
type OpenAPI3Info ¶ added in v0.2.0
type OpenAPI3Info struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
}
OpenAPI3Info describes API metadata.
type OpenAPI3Operation ¶ added in v0.2.0
type OpenAPI3Operation struct {
Summary string `json:"summary"`
Tags []string `json:"tags,omitempty"`
Parameters []OpenAPI3Parameter `json:"parameters,omitempty"`
Responses map[string]OpenAPI3Response `json:"responses"`
}
OpenAPI3Operation describes an HTTP operation on a path.
type OpenAPI3Parameter ¶ added in v0.2.0
type OpenAPI3Parameter struct {
Name string `json:"name"`
In string `json:"in"` // path, query, header
Required bool `json:"required"`
Schema map[string]string `json:"schema"`
}
OpenAPI3Parameter describes a request parameter.
type OpenAPI3Response ¶ added in v0.2.0
type OpenAPI3Response struct {
Description string `json:"description"`
}
OpenAPI3Response describes an API response.
type OpenAPI3SecurityScheme ¶ added in v0.2.0
type OpenAPI3SecurityScheme struct {
Type string `json:"type"`
Scheme string `json:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty"`
}
OpenAPI3SecurityScheme defines security schemes such as Bearer JWT.
type PaginatedData ¶
type PaginatedData struct {
Items any `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
PaginatedData is the standard pagination payload shape.