dto

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

	// Authentication errors
	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

View Source
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

func DuplicateGateName(err error) *APIError

DuplicateGateName returns an RFC 7807 error for duplicate gate names. Used when a gate with the same name already exists.

func DuplicateGateURLs

func DuplicateGateURLs(err error) *APIError

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

func GateNotFound(id string) *APIError

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

func InvalidDiffConfig(err error) *APIError

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

func InvalidGateID(id string) *APIError

InvalidGateID returns an RFC 7807 error for invalid gate ID format. Used when gate_id path parameter is not a valid UUID.

func InvalidGateName

func InvalidGateName(err error) *APIError

InvalidGateName returns an RFC 7807 error for invalid gate name. Used when the name field is empty or exceeds the maximum length.

func InvalidGatePagination

func InvalidGatePagination(err error) *APIError

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

func InvalidGateSort(err error) *APIError

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

func InvalidGateURL(err error) *APIError

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

func InvalidRedactedFields(err error) *APIError

InvalidRedactedFields returns an RFC 7807 error for invalid redacted fields configuration. Used when redacted_fields are invalid (e.g., empty field paths).

func InvalidRequestBody

func InvalidRequestBody(err error) *APIError

InvalidRequestBody returns an RFC 7807 error for malformed request bodies. Used when the request body cannot be parsed as valid JSON.

func InvalidRequestFilters

func InvalidRequestFilters(err error) *APIError

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

func InvalidRequestID(id string) *APIError

InvalidRequestID returns an RFC 7807 error for invalid request ID format. Used when request_id path parameter is not a valid UUID.

func InvalidRequestPagination

func InvalidRequestPagination(err error) *APIError

InvalidRequestPagination returns an RFC 7807 error for invalid pagination parameters. Used when limit or offset query parameters are invalid for request listing.

func InvalidRequestSort

func InvalidRequestSort(err error) *APIError

InvalidRequestSort returns an RFC 7807 error for invalid sort parameters. Used when sort or order query parameters are invalid.

func InvalidResponseBody

func InvalidResponseBody(err error) *APIError

InvalidResponseBody returns an RFC 7807 error for response encoding failures. Used when the server cannot encode a response (internal error).

func MissingBodyProperty

func MissingBodyProperty(field string) *APIError

MissingBodyProperty returns an RFC 7807 error for missing required fields. Used when a required field in the request body is missing.

func MissingHeader

func MissingHeader(header string) *APIError

MissingHeader returns an RFC 7807 error for missing required headers. Used when a required HTTP header is not provided.

func MissingPathParam

func MissingPathParam(param string) *APIError

MissingPathParam returns an RFC 7807 error for missing path parameters. Used when a required path parameter is not provided.

func MissingQueryParam

func MissingQueryParam(param string) *APIError

MissingQueryParam returns an RFC 7807 error for missing query parameters. Used when a required query parameter is not provided.

func NewError

func NewError(status int, errorType, title, detail string, err error) *APIError

NewError creates a new APIError with RFC 7807 fields.

func RequestNotFound

func RequestNotFound(id string) *APIError

RequestNotFound returns an RFC 7807 error for non-existent requests. Used when a request with the given ID does not exist in the system.

func (*APIError) Error

func (a *APIError) Error() string

Error implements the error interface

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

Jump to

Keyboard shortcuts

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