Documentation
¶
Index ¶
- type IndexKey
- type MockResponse
- type MockStorage
- func (s *MockStorage) FindResponse(path, mockID, contentType, method string) *MockResponse
- func (s *MockStorage) FindResponseBytes(pathBytes, mockIDBytes, contentTypeBytes, methodBytes []byte) *MockResponse
- func (s *MockStorage) FindResponseBytesAnyContentType(pathBytes, mockIDBytes, methodBytes []byte) *MockResponse
- func (s *MockStorage) GetMockListJSON() []byte
- func (s *MockStorage) GetStats() map[string]interface{}
- func (s *MockStorage) GetStatsJSON() []byte
- func (s *MockStorage) HasScenarios() bool
- func (s *MockStorage) ListAllMocks() []*MockResponse
- func (s *MockStorage) LoadScenarioConfig(configPath string) error
- func (s *MockStorage) MatchScenarioResponse(pathBytes, methodBytes, body []byte) *MockResponse
- func (s *MockStorage) SetTimingConfig(replayTiming bool, jitter float64)
- type NotFoundLogger
- type SSEEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IndexKey ¶
type IndexKey string
IndexKey is the key for indexing responses using string concatenation. We use a single string to allow map usage while avoiding allocations during lookup.
type MockResponse ¶
type MockResponse struct {
RequestID string `json:"request_id"`
Path string `json:"path"`
Method string `json:"method"`
MethodBytes []byte `json:"-"` // Pre-computed method as bytes to avoid allocation
MockID string `json:"mock_id"`
ContentType string `json:"content_type"`
StatusCode int `json:"status_code"`
Headers map[string]string `json:"headers"`
HeaderKeysLower map[string]string `json:"-"` // Pre-computed lowercase keys for fast lookup
Body []byte // Pre-serialized body ready to send
OriginalBody interface{} `json:"-"` // Keep for listing endpoints
FullURL string `json:"full_url"`
Delay float64 `json:"delay"` // Total request duration
SSEEvents []SSEEvent `json:"-"` // SSE events with timestamps
IsSSE bool `json:"-"` // Whether this is SSE response
}
MockResponse represents a stored mock response with pre-serialized body.
type MockStorage ¶
type MockStorage struct {
BaseDir string
Responses map[IndexKey][]*MockResponse
// ResponsesByPathMockID is indexed by "path|mockID" for Accept: */* lookups
ResponsesByPathMockID map[IndexKey][]*MockResponse
// Timing configuration
ReplayTiming bool
Jitter float64
// contains filtered or unexported fields
}
MockStorage handles loading and searching mock responses.
func NewMockStorage ¶
func NewMockStorage(baseDir string) (*MockStorage, error)
NewMockStorage creates a new MockStorage instance.
func (*MockStorage) FindResponse ¶
func (s *MockStorage) FindResponse(path, mockID, contentType, method string) *MockResponse
FindResponse is kept for backwards compatibility (mainly for tests).
func (*MockStorage) FindResponseBytes ¶
func (s *MockStorage) FindResponseBytes(pathBytes, mockIDBytes, contentTypeBytes, methodBytes []byte) *MockResponse
FindResponse finds a mock response by path, mock_id, and content_type. Zero allocations: builds key directly from []byte without string conversion.
func (*MockStorage) FindResponseBytesAnyContentType ¶ added in v1.0.5
func (s *MockStorage) FindResponseBytesAnyContentType(pathBytes, mockIDBytes, methodBytes []byte) *MockResponse
FindResponseBytesAnyContentType finds a mock response by path and mock_id, accepting any content_type. Returns the first matching response for the given method. Zero-allocation implementation: parses key inline without string splits.
func (*MockStorage) GetMockListJSON ¶
func (s *MockStorage) GetMockListJSON() []byte
GetMockListJSON returns pre-serialized JSON mock list (for serving).
func (*MockStorage) GetStats ¶
func (s *MockStorage) GetStats() map[string]interface{}
GetStats returns pre-serialized statistics (for display purposes).
func (*MockStorage) GetStatsJSON ¶
func (s *MockStorage) GetStatsJSON() []byte
GetStatsJSON returns pre-serialized JSON stats (for serving).
func (*MockStorage) HasScenarios ¶
func (s *MockStorage) HasScenarios() bool
HasScenarios returns true when scenario-based routing is active.
func (*MockStorage) ListAllMocks ¶
func (s *MockStorage) ListAllMocks() []*MockResponse
ListAllMocks returns all stored mock responses.
func (*MockStorage) LoadScenarioConfig ¶
func (s *MockStorage) LoadScenarioConfig(configPath string) error
LoadScenarioConfig enables scenario-based matching using the supplied YAML file. When scenarios are present the legacy mock-id lookup path is disabled.
func (*MockStorage) MatchScenarioResponse ¶
func (s *MockStorage) MatchScenarioResponse(pathBytes, methodBytes, body []byte) *MockResponse
MatchScenarioResponse evaluates the configured scenarios in declaration order and returns the first response whose method and filter match.
func (*MockStorage) SetTimingConfig ¶
func (s *MockStorage) SetTimingConfig(replayTiming bool, jitter float64)
SetTimingConfig configures timing replay behavior
type NotFoundLogger ¶ added in v1.0.4
type NotFoundLogger struct {
// contains filtered or unexported fields
}
NotFoundLogger writes 404 request/response pairs to JSON files.
func NewNotFoundLogger ¶ added in v1.0.4
func NewNotFoundLogger(baseDir string) (*NotFoundLogger, error)
NewNotFoundLogger creates a new logger that writes to the specified directory.
func (*NotFoundLogger) LogNotFound ¶ added in v1.0.4
func (l *NotFoundLogger) LogNotFound(ctx *fasthttp.RequestCtx) error
LogNotFound logs a 404 request with its response to a JSON file.