Documentation
¶
Index ¶
- Constants
- Variables
- func BuildFromDescriptorSet(ctx context.Context, fds *descriptorpb.FileDescriptorSet, ...) (*grpc.Server, error)
- func DefaultRedactKeys() []string
- func ErrorCodeToHTTPStatus(code codes.Code) int
- func ErrorCodeToString(code codes.Code) string
- func NewInstantExtender() *instantExtender
- func NewStubValidator() (*validator.Validate, error)
- func StubValidator(v *validator.Validate, engine *template.Engine) func(*stuber.Stub) error
- type ConnectRPCGateway
- type ErrorFormatter
- type Extender
- type GRPCServer
- type GRPCWebGateway
- type LogOptions
- type MultiProtocolGateway
- type RestServer
- func (h *RestServer) AddDescriptors(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) AddStub(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) BatchStubsDelete(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) Dashboard(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) DashboardInfo(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) DashboardOverview(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) DeleteService(w http.ResponseWriter, r *http.Request, serviceID string)
- func (h *RestServer) DeleteStubByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
- func (h *RestServer) FindByID(w http.ResponseWriter, r *http.Request, uuid rest.ID)
- func (h *RestServer) InspectStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) ListDescriptors(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) ListHistory(w http.ResponseWriter, r *http.Request, params rest.ListHistoryParams)
- func (h *RestServer) ListStubs(w http.ResponseWriter, r *http.Request, params rest.ListStubsParams)
- func (h *RestServer) ListUnusedStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) ListUsedStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) Liveness(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) MCPHandler() http.Handler
- func (h *RestServer) PurgeHistory(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) PurgeStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) Readiness(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) SearchStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) ServiceGet(w http.ResponseWriter, r *http.Request, serviceID string)
- func (h *RestServer) ServiceMethodGet(w http.ResponseWriter, r *http.Request, serviceID string, methodID string)
- func (h *RestServer) ServiceMethodsList(w http.ResponseWriter, r *http.Request, serviceID string)
- func (h *RestServer) ServicesList(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) SessionsList(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) SetPorts(p ServerPorts)
- func (h *RestServer) ValidateStub(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) VerifyCalls(w http.ResponseWriter, r *http.Request)
- type ServerLimits
- type ServerPorts
- type StreamCaptureState
- func (s *StreamCaptureState) AppendRequest(req map[string]any)
- func (s *StreamCaptureState) AppendResponseWithTiming(resp any, now time.Time)
- func (s *StreamCaptureState) HasTimedResponses() bool
- func (s *StreamCaptureState) SetLimit(limit int)
- func (s *StreamCaptureState) Snapshot() ([]map[string]any, []any)
- type StreamType
- type ValidationError
Constants ¶
const ( HealthServiceFullName = "grpc.health.v1.Health" HealthServiceName = "gripmock" )
const ( LogFieldService = "service" LogFieldMethod = "method" LogFieldPeerAddress = "peer.address" LogFieldComponent = "grpc.component" )
const (
ConnectEnvelopeHeaderSize = 5
)
Connect RPC envelope framing constants. Reference: https://connectrpc.com/docs/protocol/
Variables ¶
var ( ErrServiceIsMissing = stderrors.New("service name is missing") ErrMethodIsMissing = stderrors.New("method name is missing") ErrServiceNotRemovable = stderrors.New("service not found or not removable") ErrEmptyBody = stderrors.New("empty body") ErrFileDescriptorSetNoFiles = stderrors.New("FileDescriptorSet does not contain files") ErrResolveDescriptorDeps = stderrors.New("failed to resolve FileDescriptorSet dependencies") ErrInvalidFileDescriptorSet = stderrors.New("invalid FileDescriptorSet") ErrRegisterDescriptorFile = stderrors.New("failed to register descriptor file") ErrMCPInvalidArgument = stderrors.New("mcp invalid argument") ErrMCPToolNotFound = stderrors.New("mcp tool not found") )
Validation errors.
var ErrEnvelopeTooLarge = errors.New("connect envelope payload exceeds maximum size")
ErrEnvelopeTooLarge is returned by readConnectFrame when the peer advertises a payload larger than connectEnvelopeMaxFrameSize. After this error the reader stream is poisoned (the header was consumed but the body was not) and must not be used for further reads.
Functions ¶
func BuildFromDescriptorSet ¶ added in v3.7.0
func BuildFromDescriptorSet( ctx context.Context, fds *descriptorpb.FileDescriptorSet, budgerigar *stuber.Budgerigar, waiter Extender, recorder history.Recorder, ) (*grpc.Server, error)
func DefaultRedactKeys ¶ added in v3.23.0
func DefaultRedactKeys() []string
DefaultRedactKeys lists the metadata keys hidden from the call log unless the configuration replaces them.
func ErrorCodeToHTTPStatus ¶ added in v3.15.0
func ErrorCodeToString ¶ added in v3.15.0
func NewInstantExtender ¶ added in v3.7.0
func NewInstantExtender() *instantExtender
NewInstantExtender returns an Extender that never blocks.
func NewStubValidator ¶ added in v3.7.0
Types ¶
type ConnectRPCGateway ¶ added in v3.15.0
type ConnectRPCGateway struct {
// contains filtered or unexported fields
}
func NewConnectRPCGateway ¶ added in v3.15.0
func NewConnectRPCGateway( ctx context.Context, budgerigar *stuber.Budgerigar, descriptorRegistry *descriptors.Registry, recorder history.Recorder, proxyRoutesRef *atomic.Pointer[proxyroutes.Registry], validator *validator.Validate, errorFormatter *ErrorFormatter, engines ...*template.Engine, ) *ConnectRPCGateway
func (*ConnectRPCGateway) RequireProtocolVersion ¶ added in v3.19.0
func (g *ConnectRPCGateway) RequireProtocolVersion(require bool)
RequireProtocolVersion turns on the rejection the protocol permits: "clients should send this header. Servers and proxies may reject traffic without this header with 400 Bad Request".
func (*ConnectRPCGateway) ServeHTTP ¶ added in v3.15.0
func (g *ConnectRPCGateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ErrorFormatter ¶ added in v3.4.0
type ErrorFormatter struct{}
ErrorFormatter provides methods for formatting error messages.
func NewErrorFormatter ¶ added in v3.4.0
func NewErrorFormatter() *ErrorFormatter
NewErrorFormatter creates a new ErrorFormatter instance.
func (*ErrorFormatter) FormatStubNotFoundError ¶ added in v3.4.0
func (f *ErrorFormatter) FormatStubNotFoundError(expect localstuber.Query, result *localstuber.Result) error
FormatStubNotFoundError formats error messages for stub not found scenarios.
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
func NewGRPCServer ¶
func NewGRPCServer( network, address string, params *protoloc.Arguments, budgerigar *stuber.Budgerigar, waiter Extender, recorder history.Recorder, descriptorRegistry *descriptors.Registry, tlsConfig *tls.Config, remoteClient protosetdom.RemoteClient, otelEnabled bool, maxNestingDepth uint32, stubValidator *validator.Validate, errorFormatter *ErrorFormatter, limits ServerLimits, engines ...*template.Engine, ) *GRPCServer
func (*GRPCServer) Proxies ¶ added in v3.17.2
func (s *GRPCServer) Proxies() *proxyroutes.Registry
func (*GRPCServer) SetLogOptions ¶ added in v3.23.0
func (s *GRPCServer) SetLogOptions(opts LogOptions)
SetLogOptions replaces what the call log keeps; call it before Build.
type GRPCWebGateway ¶ added in v3.17.0
type GRPCWebGateway struct {
// contains filtered or unexported fields
}
GRPCWebGateway proxies gRPC-Web HTTP requests to the gRPC mocker. It translates between gRPC-Web framing (length-prefixed messages + trailers with grpc-status/grpc-message) and the shared mocker.
func NewGRPCWebGateway ¶ added in v3.17.0
func NewGRPCWebGateway( ctx context.Context, budgerigar *stuber.Budgerigar, descriptorRegistry *descriptors.Registry, recorder history.Recorder, proxyRoutesRef *atomic.Pointer[proxyroutes.Registry], validator *validator.Validate, errorFormatter *ErrorFormatter, engines ...*template.Engine, ) *GRPCWebGateway
func (*GRPCWebGateway) ServeHTTP ¶ added in v3.17.0
func (g *GRPCWebGateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
type LogOptions ¶ added in v3.23.0
LogOptions controls how much of a call reaches the log. Build it with DefaultLogOptions: the zero value neither redacts metadata nor logs bodies.
func DefaultLogOptions ¶ added in v3.23.0
func DefaultLogOptions() LogOptions
DefaultLogOptions redacts the well-known credential headers and logs bodies.
type MultiProtocolGateway ¶ added in v3.17.0
type MultiProtocolGateway struct {
// contains filtered or unexported fields
}
MultiProtocolGateway dispatches to the ConnectRPC or gRPC-Web handler based on the request Content-Type. This lets both protocols share a single HTTP port.
- application/grpc-web+proto, application/grpc-web+json → gRPC-Web
- everything else (application/json, application/proto, application/connect+proto, application/connect+json, …) → ConnectRPC
Both handlers read mux.Vars from the request context, which the gorilla/mux router populates before calling ServeHTTP.
func NewMultiProtocolGateway ¶ added in v3.17.0
func NewMultiProtocolGateway( ctx context.Context, budgerigar *stuber.Budgerigar, descriptorRegistry *descriptors.Registry, recorder history.Recorder, proxyRoutesRef *atomic.Pointer[proxyroutes.Registry], validator *validator.Validate, errorFormatter *ErrorFormatter, engines ...*template.Engine, ) *MultiProtocolGateway
func (*MultiProtocolGateway) RequireProtocolVersion ¶ added in v3.19.0
func (g *MultiProtocolGateway) RequireProtocolVersion(require bool)
RequireProtocolVersion applies only to Connect: gRPC-Web has no such header.
func (*MultiProtocolGateway) ServeHTTP ¶ added in v3.17.0
func (g *MultiProtocolGateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RestServer ¶
type RestServer struct {
// contains filtered or unexported fields
}
RestServer handles HTTP REST API requests for stub management.
func NewRestServer ¶
func NewRestServer( ctx context.Context, budgerigar *stuber.Budgerigar, extender Extender, historyReader history.Reader, stubValidator *validator.Validate, registry *descriptors.Registry, errorFormatter *ErrorFormatter, engines ...*template.Engine, ) (*RestServer, error)
NewRestServer creates a new REST server instance with the specified dependencies. If historyReader is nil, /api/history and /api/verify return empty/error. If stubValidator is nil, a new default validator is created automatically.
func (*RestServer) AddDescriptors ¶ added in v3.7.0
func (h *RestServer) AddDescriptors(w http.ResponseWriter, r *http.Request)
AddDescriptors accepts binary FileDescriptorSet and registers it for discovery. Returns service IDs; use DELETE /services/{serviceID} to remove.
func (*RestServer) AddStub ¶
func (h *RestServer) AddStub(w http.ResponseWriter, r *http.Request)
func (*RestServer) BatchStubsDelete ¶
func (h *RestServer) BatchStubsDelete(w http.ResponseWriter, r *http.Request)
BatchStubsDelete removes multiple stubs by ID.
func (*RestServer) Dashboard ¶ added in v3.8.2
func (h *RestServer) Dashboard(w http.ResponseWriter, r *http.Request)
Dashboard returns combined counters and runtime metadata for dashboard page.
func (*RestServer) DashboardInfo ¶ added in v3.8.2
func (h *RestServer) DashboardInfo(w http.ResponseWriter, r *http.Request)
DashboardInfo returns build metadata and runtime process information.
func (*RestServer) DashboardOverview ¶ added in v3.8.2
func (h *RestServer) DashboardOverview(w http.ResponseWriter, r *http.Request)
DashboardOverview returns aggregated lightweight metrics for admin dashboard.
func (*RestServer) DeleteService ¶ added in v3.7.0
func (h *RestServer) DeleteService(w http.ResponseWriter, r *http.Request, serviceID string)
DeleteService removes a service added via POST /descriptors. Services from startup (proto path) cannot be removed and return 404.
func (*RestServer) DeleteStubByID ¶
func (h *RestServer) DeleteStubByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
func (*RestServer) FindByID ¶
func (h *RestServer) FindByID(w http.ResponseWriter, r *http.Request, uuid rest.ID)
FindByID returns a stub by ID.
func (*RestServer) InspectStubs ¶ added in v3.8.2
func (h *RestServer) InspectStubs(w http.ResponseWriter, r *http.Request)
InspectStubs returns detailed matching report for a query.
func (*RestServer) ListDescriptors ¶ added in v3.7.0
func (h *RestServer) ListDescriptors(w http.ResponseWriter, r *http.Request)
func (*RestServer) ListHistory ¶ added in v3.7.0
func (h *RestServer) ListHistory(w http.ResponseWriter, r *http.Request, params rest.ListHistoryParams)
ListHistory returns recorded gRPC calls.
func (*RestServer) ListStubs ¶
func (h *RestServer) ListStubs(w http.ResponseWriter, r *http.Request, params rest.ListStubsParams)
ListStubs returns all stubs, optionally filtered by source.
func (*RestServer) ListUnusedStubs ¶
func (h *RestServer) ListUnusedStubs(w http.ResponseWriter, r *http.Request)
ListUnusedStubs returns stubs that have never been matched.
func (*RestServer) ListUsedStubs ¶
func (h *RestServer) ListUsedStubs(w http.ResponseWriter, r *http.Request)
ListUsedStubs returns stubs that have been matched.
func (*RestServer) Liveness ¶
func (h *RestServer) Liveness(w http.ResponseWriter, r *http.Request)
Liveness handles the liveness probe endpoint.
func (*RestServer) MCPHandler ¶ added in v3.8.7
func (h *RestServer) MCPHandler() http.Handler
func (*RestServer) PurgeHistory ¶ added in v3.20.0
func (h *RestServer) PurgeHistory(w http.ResponseWriter, r *http.Request)
PurgeHistory deletes recorded calls, scoped to the request's session when set.
func (*RestServer) PurgeStubs ¶
func (h *RestServer) PurgeStubs(w http.ResponseWriter, r *http.Request)
PurgeStubs removes stubs, scoped to the request's session when one is set. Without the scope a session-bound client would wipe every other session's stubs, which is not what DELETE /api/history or the MCP stubs_purge tool do.
func (*RestServer) Readiness ¶
func (h *RestServer) Readiness(w http.ResponseWriter, r *http.Request)
func (*RestServer) SearchStubs ¶
func (h *RestServer) SearchStubs(w http.ResponseWriter, r *http.Request)
SearchStubs finds a stub matching the query.
func (*RestServer) ServiceGet ¶ added in v3.8.2
func (h *RestServer) ServiceGet(w http.ResponseWriter, r *http.Request, serviceID string)
ServiceGet returns exact service metadata by id.
func (*RestServer) ServiceMethodGet ¶ added in v3.8.2
func (h *RestServer) ServiceMethodGet(w http.ResponseWriter, r *http.Request, serviceID string, methodID string)
ServiceMethodGet returns exact method metadata by service and method id.
func (*RestServer) ServiceMethodsList ¶
func (h *RestServer) ServiceMethodsList(w http.ResponseWriter, r *http.Request, serviceID string)
ServiceMethodsList returns a list of methods for the specified service.
func (*RestServer) ServicesList ¶
func (h *RestServer) ServicesList(w http.ResponseWriter, r *http.Request)
ServicesList returns a list of all available gRPC services (startup + REST-added).
func (*RestServer) SessionsList ¶ added in v3.8.2
func (h *RestServer) SessionsList(w http.ResponseWriter, r *http.Request)
SessionsList returns distinct non-empty session IDs for UI selectors.
func (*RestServer) SetPorts ¶ added in v3.18.0
func (h *RestServer) SetPorts(p ServerPorts)
SetPorts records the protocol listen addresses for the dashboard (optional).
func (*RestServer) ValidateStub ¶ added in v3.18.0
func (h *RestServer) ValidateStub(w http.ResponseWriter, r *http.Request)
ValidateStub dry-runs validation over the posted stubs without persisting them.
func (*RestServer) VerifyCalls ¶ added in v3.7.0
func (h *RestServer) VerifyCalls(w http.ResponseWriter, r *http.Request)
VerifyCalls verifies that a method was called the expected number of times.
type ServerLimits ¶ added in v3.19.0
type ServerLimits struct {
MaxRecvMsgSize int
MaxSendMsgSize int
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
KeepaliveMaxConnectionIdle time.Duration
KeepaliveMaxConnectionAge time.Duration
}
func DefaultServerLimits ¶ added in v3.19.0
func DefaultServerLimits() ServerLimits
type ServerPorts ¶ added in v3.18.0
type ServerPorts struct {
GRPC string // native gRPC
Gateway string // ConnectRPC + gRPC-web (one port)
HTTP string // admin REST API + this UI
}
ServerPorts holds the listen addresses of the protocol endpoints, surfaced on the dashboard so users know where to point clients.
type StreamCaptureState ¶ added in v3.15.0
type StreamCaptureState struct {
// contains filtered or unexported fields
}
func NewStreamCaptureState ¶ added in v3.15.0
func NewStreamCaptureState() *StreamCaptureState
func (*StreamCaptureState) AppendRequest ¶ added in v3.15.0
func (s *StreamCaptureState) AppendRequest(req map[string]any)
func (*StreamCaptureState) AppendResponseWithTiming ¶ added in v3.15.1
func (s *StreamCaptureState) AppendResponseWithTiming(resp any, now time.Time)
func (*StreamCaptureState) HasTimedResponses ¶ added in v3.15.1
func (s *StreamCaptureState) HasTimedResponses() bool
HasTimedResponses returns true if at least one response was captured with per-element delay.
func (*StreamCaptureState) SetLimit ¶ added in v3.23.0
func (s *StreamCaptureState) SetLimit(limit int)
type StreamType ¶ added in v3.15.0
type StreamType int
const ( StreamTypeUnary StreamType = iota StreamTypeServer StreamTypeClient StreamTypeBidi )
type ValidationError ¶ added in v3.4.0
func (ValidationError) Error ¶ added in v3.4.0
func (e ValidationError) Error() string
Source Files
¶
- connect_envelope.go
- connect_gateway.go
- connect_get.go
- connect_handler.go
- constants.go
- convert.go
- convert_wellknown.go
- errors.go
- extender.go
- gateway_body_limit.go
- gateway_frame_compression.go
- gateway_reflection.go
- gateway_shared.go
- gateway_timeout.go
- grpc_effects.go
- grpc_logging.go
- grpc_mocker_bidi.go
- grpc_mocker_stream.go
- grpc_mocker_unary.go
- grpc_proxy_build.go
- grpc_proxy_common.go
- grpc_proxy_fallback.go
- grpc_proxy_record.go
- grpc_proxy_stream.go
- grpc_proxy_unary.go
- grpc_registration.go
- grpc_server.go
- grpc_session.go
- grpc_status_details.go
- grpcweb_gateway.go
- grpcweb_text.go
- health_codec.go
- health_handler.go
- health_query.go
- multiprotocol_gateway.go
- output_document.go
- output_render.go
- output_runtime_common.go
- proxy_behavior.go
- rest_dashboard.go
- rest_descriptors.go
- rest_mcp.go
- rest_mcp_args.go
- rest_mcp_mockcall.go
- rest_mcp_stubs.go
- rest_mcp_tools.go
- rest_schema.go
- rest_server.go
- rest_stubs.go
- server_limits.go
- streaming_capture.go
- utils_copy.go
- validation.go