Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- func DuplicateGateName(err error) *APIError
- func DuplicateGateURLs(err error) *APIError
- func GateNotFound(id string) *APIError
- func InvalidDiffConfig(err error) *APIError
- func InvalidGateID(id string) *APIError
- func InvalidGateName(err error) *APIError
- func InvalidGatePagination(err error) *APIError
- func InvalidGateSort(err error) *APIError
- func InvalidGateURL(err error) *APIError
- func InvalidRedactedFields(err error) *APIError
- func InvalidRequestBody(err error) *APIError
- func InvalidRequestFilters(err error) *APIError
- func InvalidRequestID(id string) *APIError
- func InvalidRequestPagination(err error) *APIError
- func InvalidRequestSort(err error) *APIError
- func InvalidResponseBody(err error) *APIError
- func MissingBodyProperty(field string) *APIError
- func MissingHeader(header string) *APIError
- func MissingPathParam(param string) *APIError
- func MissingQueryParam(param string) *APIError
- func NewError(status int, errorType, title, detail string, err error) *APIError
- func RequestNotFound(id string) *APIError
- type CreateRequestPayload
- type DiffConfig
- type DiffDetail
- type DiffPayload
- type Gate
- type GateStats
- type GlobalStats
- type PaginatedResponse
- type PaginationMeta
- type Request
- type RequestDetail
- type Response
- type ResponseDetail
- type ResponsePayload
- type ResponseSummary
Constants ¶
const ( // Request body errors ErrorTypeInvalidRequestBody = "/errors/invalid-request-body" // Malformed JSON or validation failures // Parameter errors (by source) ErrorTypeMissingPathParam = "/errors/missing-path-param" // Required path parameter missing ErrorTypeMissingQueryParam = "/errors/missing-query-param" // Required query parameter missing ErrorTypeMissingHeader = "/errors/missing-header" // Required header missing ErrorTypeMissingBodyField = "/errors/missing-body-field" // Required body field missing ErrorTypeInvalidQueryParam = "/errors/invalid-query-param" // Query parameter invalid ErrorTypeUnauthorized = "/errors/unauthorized" // Missing or invalid credentials // Rate limiting errors ErrorTypeRateLimitExceeded = "/errors/rate-limit-exceeded" // Too many requests // Resource errors ErrorTypeNotFound = "/errors/not-found" // Resource doesn't exist ErrorTypeConflict = "/errors/conflict" // Resource already exists // Server errors ErrorTypeInternalError = "/errors/internal-error" // Server error )
Generic HTTP error type constants (relative paths)
Variables ¶
var ( ErrMissingAuthHeader = &APIError{ Type: ErrorTypeUnauthorized, Title: "Missing Authorization Header", Status: http.StatusUnauthorized, Detail: "Authorization header is required", Err: errors.New("missing authorization header"), } ErrInvalidAuthFormat = &APIError{ Type: ErrorTypeUnauthorized, Title: "Invalid Authorization Format", Status: http.StatusUnauthorized, Detail: "Authorization header must use format: Bearer <token>", Err: errors.New("invalid authorization format"), } ErrInvalidAPIKey = &APIError{ Type: ErrorTypeUnauthorized, Title: "Invalid API Key", Status: http.StatusUnauthorized, Detail: "The provided API key is not valid", Err: errors.New("invalid api key"), } ErrRateLimitExceeded = &APIError{ Type: ErrorTypeRateLimitExceeded, Title: "Rate Limit Exceeded", Status: http.StatusTooManyRequests, Detail: "Rate limit exceeded. Please retry after 60 seconds (Retry-After: 60).", Err: errors.New("rate limit exceeded"), } )
Static authentication errors
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Type string `json:"type"` // URI reference identifying the error type
Title string `json:"title"` // Short, human-readable summary
Status int `json:"status"` // HTTP status code
Detail string `json:"detail,omitempty"` // Human-readable explanation
Instance string `json:"instance,omitempty"` // URI reference to error occurrence
Err error `json:"-"` // Internal error (not serialized)
}
APIError represents an RFC 7807 Problem Detail error response. It is serialized directly as the error response body.
func DuplicateGateName ¶
DuplicateGateName returns an RFC 7807 error for duplicate gate names. Used when a gate with the same name already exists.
func DuplicateGateURLs ¶
DuplicateGateURLs returns an RFC 7807 error for duplicate gate URL pairs. Used when a gate with the same live_url + shadow_url combination already exists.
func GateNotFound ¶
GateNotFound returns an RFC 7807 error for non-existent gates. Used when a gate with the given ID does not exist in the system.
func InvalidDiffConfig ¶
InvalidDiffConfig returns an RFC 7807 error for invalid diff configuration. Used when diff_config fields are invalid (e.g., negative float tolerance, empty field paths).
func InvalidGateID ¶
InvalidGateID returns an RFC 7807 error for invalid gate ID format. Used when gate_id path parameter is not a valid UUID.
func InvalidGateName ¶
InvalidGateName returns an RFC 7807 error for invalid gate name. Used when the name field is empty or exceeds the maximum length.
func InvalidGatePagination ¶
InvalidGatePagination returns an RFC 7807 error for invalid pagination parameters. Used when limit or offset query parameters are invalid (e.g., negative values).
func InvalidGateSort ¶
InvalidGateSort returns an RFC 7807 error for invalid gate sort parameters. Used when sort or order query parameters are invalid for gate listing.
func InvalidGateURL ¶
InvalidGateURL returns an RFC 7807 error for invalid gate URL format. Used when live_url or shadow_url use invalid schemes (must be http/https).
func InvalidRedactedFields ¶ added in v1.1.0
InvalidRedactedFields returns an RFC 7807 error for invalid redacted fields configuration. Used when redacted_fields are invalid (e.g., empty field paths).
func InvalidRequestBody ¶
InvalidRequestBody returns an RFC 7807 error for malformed request bodies. Used when the request body cannot be parsed as valid JSON.
func InvalidRequestFilters ¶
InvalidRequestFilters returns an RFC 7807 error for invalid filter parameters. Used when request filter query parameters (methods, path_pattern, from_date, to_date, or has_diff) are invalid.
func InvalidRequestID ¶
InvalidRequestID returns an RFC 7807 error for invalid request ID format. Used when request_id path parameter is not a valid UUID.
func InvalidRequestPagination ¶
InvalidRequestPagination returns an RFC 7807 error for invalid pagination parameters. Used when limit or offset query parameters are invalid for request listing.
func InvalidRequestSort ¶
InvalidRequestSort returns an RFC 7807 error for invalid sort parameters. Used when sort or order query parameters are invalid.
func InvalidResponseBody ¶
InvalidResponseBody returns an RFC 7807 error for response encoding failures. Used when the server cannot encode a response (internal error).
func MissingBodyProperty ¶
MissingBodyProperty returns an RFC 7807 error for missing required fields. Used when a required field in the request body is missing.
func MissingHeader ¶
MissingHeader returns an RFC 7807 error for missing required headers. Used when a required HTTP header is not provided.
func MissingPathParam ¶
MissingPathParam returns an RFC 7807 error for missing path parameters. Used when a required path parameter is not provided.
func MissingQueryParam ¶
MissingQueryParam returns an RFC 7807 error for missing query parameters. Used when a required query parameter is not provided.
func RequestNotFound ¶
RequestNotFound returns an RFC 7807 error for non-existent requests. Used when a request with the given ID does not exist in the system.
type CreateRequestPayload ¶
type CreateRequestPayload struct {
// Request metadata
ID string `json:"id,omitempty"` // Optional: API will generate if empty
Method string `json:"method"` // e.g., "GET", "POST"
Path string `json:"path"` // e.g., "/api/users/123"
RawQuery string `json:"raw_query,omitempty"` // e.g., "page=2&limit=10"
Headers map[string][]string `json:"headers"` // HTTP headers
Body string `json:"body"` // Base64 encoded
CreatedAt time.Time `json:"created_at"` // When request was captured
// Responses from both services
LiveResponse ResponsePayload `json:"live_response"`
ShadowResponse ResponsePayload `json:"shadow_response"`
// Computed diff (optional — if omitted, mroki-api computes it server-side)
Diff *DiffPayload `json:"diff,omitempty"`
}
CreateRequestPayload represents the payload for creating a request with responses and diff. This is sent from proxies to the API.
type DiffConfig ¶
type DiffConfig struct {
IgnoredFields []string `json:"ignored_fields"`
IncludedFields []string `json:"included_fields"`
FloatTolerance float64 `json:"float_tolerance"`
}
DiffConfig holds per-gate diff computation settings.
type DiffDetail ¶
type DiffDetail struct {
Content []diff.PatchOp `json:"content"` // RFC 6902 JSON Patch operations
}
DiffDetail represents diff content (used in request detail view).
type DiffPayload ¶
type DiffPayload struct {
Content []diff.PatchOp `json:"content"` // RFC 6902 JSON Patch operations
}
DiffPayload contains the computed difference between responses.
type Gate ¶
type Gate struct {
ID string `json:"id"`
Name string `json:"name"`
LiveURL string `json:"live_url"`
ShadowURL string `json:"shadow_url"`
DiffConfig DiffConfig `json:"diff_config"`
RedactedFields []string `json:"redacted_fields"`
CreatedAt string `json:"created_at"`
Stats GateStats `json:"stats"`
}
Gate represents a traffic testing gate with live and shadow URLs.
type GateStats ¶
type GateStats struct {
RequestCount24h int64 `json:"request_count_24h"`
DiffCount24h int64 `json:"diff_count_24h"`
DiffRate float64 `json:"diff_rate"`
LastActive *string `json:"last_active"`
}
GateStats holds computed statistics for a single gate.
type GlobalStats ¶
type GlobalStats struct {
TotalGates int64 `json:"total_gates"`
TotalRequests24h int64 `json:"total_requests_24h"`
TotalDiffRate float64 `json:"total_diff_rate"`
}
GlobalStats holds cross-gate aggregate statistics.
type PaginatedResponse ¶
type PaginatedResponse[T any] struct { Data T `json:"data"` Pagination PaginationMeta `json:"pagination"` }
PaginatedResponse is a generic wrapper for paginated API responses.
type PaginationMeta ¶
type PaginationMeta struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Total int64 `json:"total"`
HasMore bool `json:"has_more"`
}
PaginationMeta represents pagination metadata for API responses.
type Request ¶
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Path string `json:"path"`
RawQuery string `json:"raw_query,omitempty"`
CreatedAt time.Time `json:"created_at"`
LiveResponse *ResponseSummary `json:"live_response"`
ShadowResponse *ResponseSummary `json:"shadow_response"`
HasDiff bool `json:"has_diff"`
}
Request represents a summary of a captured request (used in listings).
type RequestDetail ¶
type RequestDetail struct {
ID string `json:"id"`
Method string `json:"method"`
Path string `json:"path"`
RawQuery string `json:"raw_query,omitempty"`
Headers map[string][]string `json:"headers"`
Body *string `json:"body"`
CreatedAt time.Time `json:"created_at"`
LiveResponse ResponseDetail `json:"live_response"`
ShadowResponse ResponseDetail `json:"shadow_response"`
Diff DiffDetail `json:"diff"`
}
RequestDetail represents a complete request with all responses and diff.
type Response ¶
type Response[T any] struct { Data T `json:"data"` }
Response is a generic wrapper for successful API responses.
type ResponseDetail ¶
type ResponseDetail struct {
ID string `json:"id"`
StatusCode int `json:"status_code"`
Headers http.Header `json:"headers"`
Body *string `json:"body"`
LatencyMs int64 `json:"latency_ms"`
CreatedAt time.Time `json:"created_at"`
}
ResponseDetail represents a response with full details (used in request detail view).
type ResponsePayload ¶
type ResponsePayload struct {
ID string `json:"id,omitempty"` // Optional
StatusCode int `json:"status_code"` // e.g., 200, 404, 500
Headers map[string][]string `json:"headers"` // Response headers
Body string `json:"body"` // Base64 encoded
LatencyMs int64 `json:"latency_ms"` // Response time in milliseconds
CreatedAt time.Time `json:"created_at"` // Same as request
}
ResponsePayload represents a single HTTP response.
type ResponseSummary ¶
type ResponseSummary struct {
StatusCode int `json:"status_code"`
LatencyMs int64 `json:"latency_ms"`
}
ResponseSummary represents a lightweight response summary (used in listings).