Documentation
¶
Index ¶
- Constants
- Variables
- func LogStreamInterceptor(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func LogUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, ...) (any, error)
- type ErrorFormatter
- func (f *ErrorFormatter) CreateClientStreamError(serviceName, methodName string, err error) error
- func (f *ErrorFormatter) CreateStubNotFoundError(serviceName, methodName string, details ...string) error
- func (f *ErrorFormatter) FormatStubNotFoundError(expect localstuber.Query, result *localstuber.Result) error
- func (f *ErrorFormatter) FormatStubNotFoundErrorV2(expect localstuber.QueryV2, result *localstuber.Result) error
- type Extender
- type GRPCServer
- type MessageConverter
- type RestServer
- func (h *RestServer) AddStub(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) BatchStubsDelete(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) DeleteStubByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
- func (h *RestServer) FindByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
- func (h *RestServer) ListStubs(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) ListUnusedStubs(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) ListUsedStubs(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) Liveness(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) PurgeStubs(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) Readiness(w http.ResponseWriter, _ *http.Request)
- func (h *RestServer) SearchStubs(w http.ResponseWriter, r *http.Request)
- func (h *RestServer) ServiceMethodsList(w http.ResponseWriter, _ *http.Request, serviceID string)
- func (h *RestServer) ServicesList(w http.ResponseWriter, _ *http.Request)
- type ValidationError
Constants ¶
const ( // ServiceReflection is the name of the gRPC reflection service. ServiceReflection = "grpc.reflection.v1.ServerReflection" // DefaultTimeout is the default timeout for operations. DefaultTimeout = 30 // HealthServiceName defines the service name used for gRPC health checks. // It is referenced by health check mechanisms to identify the service being checked. HealthServiceName = "gripmock" )
Constants for gRPC server configuration.
const ( ErrMsgFailedToSendResponse = "failed to send response" ErrMsgFailedToReceiveMessage = "failed to receive message" ErrMsgFailedToSetHeaders = "failed to set headers" ErrMsgFailedToConvertResponse = "failed to convert response to dynamic message" ErrMsgFailedToProcessMessage = "failed to process bidirectional message" ErrMsgFailedToInitializeStream = "failed to initialize bidirectional streaming session" ErrMsgFailedToBuildDescriptors = "failed to build descriptors" ErrMsgFailedToFindStub = "failed to find stub" ErrMsgFailedToMarshalData = "failed to marshal expect data" )
Error messages.
const ( LogFieldService = "service" LogFieldMethod = "method" LogFieldPeerAddress = "peer.address" LogFieldProtocol = "protocol" LogFieldTimeMs = "grpc.time_ms" LogFieldCode = "grpc.code" LogFieldComponent = "grpc.component" LogFieldMetadata = "grpc.metadata" LogFieldRequest = "grpc.request.content" LogFieldResponse = "grpc.response.content" LogFieldMethodType = "grpc.method_type" )
Logging constants.
Variables ¶
var ( ErrInputCannotBeEmpty = errors.New("input/inputs cannot be empty") ErrOutputCannotBeEmpty = errors.New("output/output.stream cannot be empty") ErrInputsCannotBeEmptyForClient = errors.New("inputs cannot be empty for client streaming") ErrStreamCannotBeEmptyForServer = errors.New("output.stream cannot be empty for server streaming") ErrInputsCannotBeEmptyForBidi = errors.New("inputs cannot be empty for bidirectional streaming") ErrStreamCannotBeEmptyForBidi = errors.New("output.stream cannot be empty for bidirectional streaming") ErrInvalidStubConfiguration = errors.New("invalid stub configuration") ErrInvalidInputConfiguration = errors.New("cannot have both input and inputs configured") ErrInvalidOutputConfiguration = errors.New("cannot have both output.data and output.stream configured") )
Validation errors.
var ErrMethodIsMissing = errors.New("method name is missing")
ErrMethodIsMissing is returned when the method name is not provided in the request.
var ErrServiceIsMissing = errors.New("service name is missing")
ErrServiceIsMissing is returned when the service name is not provided in the request.
var ExcludedHeaders = []string{
":authority",
"content-type",
"grpc-accept-encoding",
"user-agent",
"accept-encoding",
}
ExcludedHeaders contains headers that should be excluded from stub matching.
Functions ¶
func LogStreamInterceptor ¶
func LogStreamInterceptor(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
func LogUnaryInterceptor ¶
func LogUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)
Types ¶
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) CreateClientStreamError ¶ added in v3.4.0
func (f *ErrorFormatter) CreateClientStreamError(serviceName, methodName string, err error) error
CreateClientStreamError creates a gRPC status error for client stream scenarios.
func (*ErrorFormatter) CreateStubNotFoundError ¶ added in v3.4.0
func (f *ErrorFormatter) CreateStubNotFoundError(serviceName, methodName string, details ...string) error
CreateStubNotFoundError creates a gRPC status error for stub not found scenarios.
func (*ErrorFormatter) FormatStubNotFoundError ¶ added in v3.4.0
func (f *ErrorFormatter) FormatStubNotFoundError(expect localstuber.Query, result *localstuber.Result) error
FormatStubNotFoundError formats error messages for V1 API stub not found scenarios.
func (*ErrorFormatter) FormatStubNotFoundErrorV2 ¶ added in v3.4.0
func (f *ErrorFormatter) FormatStubNotFoundErrorV2(expect localstuber.QueryV2, result *localstuber.Result) error
FormatStubNotFoundErrorV2 formats error messages for V2 API 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, ) *GRPCServer
type MessageConverter ¶ added in v3.4.0
type MessageConverter struct{}
MessageConverter provides methods for converting protobuf messages to map representations.
func NewMessageConverter ¶ added in v3.4.0
func NewMessageConverter() *MessageConverter
NewMessageConverter creates a new MessageConverter instance.
func (*MessageConverter) ConvertToMap ¶ added in v3.4.0
func (c *MessageConverter) ConvertToMap(msg proto.Message) map[string]any
ConvertToMap converts a protobuf message to a map[string]any representation.
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, ) (*RestServer, error)
NewRestServer creates a new REST server instance with the specified dependencies.
func (*RestServer) AddStub ¶
func (h *RestServer) AddStub(w http.ResponseWriter, r *http.Request)
AddStub adds a new stub to the server.
func (*RestServer) BatchStubsDelete ¶
func (h *RestServer) BatchStubsDelete(w http.ResponseWriter, r *http.Request)
BatchStubsDelete deletes multiple stubs in a batch operation.
func (*RestServer) DeleteStubByID ¶
func (h *RestServer) DeleteStubByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
DeleteStubByID deletes a stub by its ID.
func (*RestServer) FindByID ¶
func (h *RestServer) FindByID(w http.ResponseWriter, _ *http.Request, uuid rest.ID)
FindByID retrieves a stub by its ID.
func (*RestServer) ListStubs ¶
func (h *RestServer) ListStubs(w http.ResponseWriter, _ *http.Request)
ListStubs returns a list of all stubs.
func (*RestServer) ListUnusedStubs ¶
func (h *RestServer) ListUnusedStubs(w http.ResponseWriter, _ *http.Request)
ListUnusedStubs returns a list of stubs that have not been used.
func (*RestServer) ListUsedStubs ¶
func (h *RestServer) ListUsedStubs(w http.ResponseWriter, _ *http.Request)
ListUsedStubs returns a list of stubs that have been used.
func (*RestServer) Liveness ¶
func (h *RestServer) Liveness(w http.ResponseWriter, _ *http.Request)
Liveness handles the liveness probe endpoint.
func (*RestServer) PurgeStubs ¶
func (h *RestServer) PurgeStubs(w http.ResponseWriter, _ *http.Request)
PurgeStubs clears all stubs from the server.
func (*RestServer) Readiness ¶
func (h *RestServer) Readiness(w http.ResponseWriter, _ *http.Request)
Readiness handles the readiness probe endpoint.
func (*RestServer) SearchStubs ¶
func (h *RestServer) SearchStubs(w http.ResponseWriter, r *http.Request)
SearchStubs searches for stubs based on a query.
func (*RestServer) ServiceMethodsList ¶
func (h *RestServer) ServiceMethodsList(w http.ResponseWriter, _ *http.Request, serviceID string)
ServiceMethodsList returns a list of methods for the specified service.
func (*RestServer) ServicesList ¶
func (h *RestServer) ServicesList(w http.ResponseWriter, _ *http.Request)
ServicesList returns a list of all available gRPC services.
type ValidationError ¶ added in v3.4.0
ValidationError represents a validation error with field information.
func (ValidationError) Error ¶ added in v3.4.0
func (e ValidationError) Error() string