### Install and configure protoc-gen-grpchan path Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Install the plugin and ensure the binary location is included in the system PATH. ```bash go install github.com/fullstorydev/grpchan/cmd/protoc-gen-grpchan # If necessary, make sure its location is on your path like so: # export PATH=$PATH:$GOPATH/bin ``` -------------------------------- ### Install protoc-gen-grpchan Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Install the protoc plugin required for generating grpchan-compatible service code. ```bash go install github.com/fullstorydev/grpchan/cmd/protoc-gen-grpchan ``` -------------------------------- ### Get Service Information Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc GetServiceInfo returns information about the registered services. This is used to implement the reflection.GRPCServer interface for server reflection. ```go func (s *Server) GetServiceInfo() map[string]grpc.ServiceInfo ``` -------------------------------- ### Get Service Information from HandlerMap Source: https://pkg.go.dev/github.com/fullstorydev/grpchan GetServiceInfo returns a snapshot of information about the currently registered services in the map. This mirrors the method of the same name on *grpc.Server. ```go func (m HandlerMap) GetServiceInfo() map[string]grpc.ServiceInfo ``` -------------------------------- ### Get Method Name from ServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Method satisfies the grpc.ServerTransportStream, returning the full path of the method invocation that the stream represents. ```go func (sts *ServerTransportStream) Method() string ``` -------------------------------- ### Get Method Name from UnaryServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Method satisfies the grpc.ServerTransportStream, returning the full path of the method invocation that the stream represents. ```go func (sts *UnaryServerTransportStream) Method() string ``` -------------------------------- ### Get Trailer Values Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc GetValues returns the slice of string values stored in the TrailerValues. ```go func (x *TrailerValues) GetValues() []string ``` -------------------------------- ### NewServer Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Initializes a new gRPC-over-HTTP server instance. ```APIDOC ## NewServer ### Description Returns a new gRPC-over-HTTP server. The server can be customized using various ServerOption instances. ### Parameters #### Request Body - **opts** (ServerOption) - Optional - A variadic list of options to configure the server behavior. ``` -------------------------------- ### Create New Server Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc NewServer returns a new gRPC-over-HTTP server. Options can be provided to customize its behavior. ```go func NewServer(opts ...ServerOption) *Server ``` -------------------------------- ### Generate grpchan code with protoc Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Use the protoc plugin to generate *.pb.grpchan.go files alongside standard Go protobuf files. ```bash //go:generate protoc --go_out=plugins=grpc:. --grpchan_out=. my.proto ``` -------------------------------- ### New Test Service Client Constructor Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Use this constructor to create a new TestServiceClient. ```go func NewTestServiceClient(cc grpc.ClientConnInterface) TestServiceClient ``` -------------------------------- ### Run Channel Test Cases Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Executes test cases to verify channel behavior, requiring a registered TestServer. ```go func RunChannelTestCases(t *testing.T, ch grpc.ClientConnInterface, supportsFullDuplex bool) ``` -------------------------------- ### Get Trailers from UnaryServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal GetTrailers returns the cumulative set of trailers set by calls to SetTrailer. This is used by a server to gather trailers to be sent to a client. ```go func (sts *UnaryServerTransportStream) GetTrailers() metadata.MD ``` -------------------------------- ### TestServer Implementation Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Server implementation providing default responses for TestService methods. ```go type TestServer struct { UnimplementedTestServiceServer } ``` ```go func (s *TestServer) BidiStream(str TestService_BidiStreamServer) error ``` ```go func (s *TestServer) ClientStream(cs TestService_ClientStreamServer) error ``` ```go func (s *TestServer) ServerStream(req *Message, ss TestService_ServerStreamServer) error ``` ```go func (s *TestServer) Unary(ctx context.Context, req *Message) (*Message, error) ``` ```go func (s *TestServer) UseExternalMessageTwice(ctx context.Context, in *empty.Empty) (*empty.Empty, error) ``` -------------------------------- ### Get Headers from UnaryServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal GetHeaders returns the cumulative set of headers set by calls to SetHeader and SendHeader. This is used by a server to gather headers to be sent to a client. ```go func (sts *UnaryServerTransportStream) GetHeaders() metadata.MD ``` -------------------------------- ### Generate legacy stubs with protoc Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Use the legacy_stubs option to generate older client channel methods. ```bash protoc foo.proto --grpchan_out=legacy_stubs:./output/dir ``` -------------------------------- ### Serve HTTP Requests Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc ServeHTTP implements the http.Handler interface, enabling the server to be attached to an http.Server for exposing registered services to HTTP clients. ```go func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) ``` -------------------------------- ### Register Service Implementation Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc RegisterService registers a service and its implementation. Similar to a standard gRPC server, only one implementation is allowed per service, identified by its fully-qualified name. ```go func (s *Server) RegisterService(desc *grpc.ServiceDesc, svr interface{}) ``` -------------------------------- ### ServeHTTP Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Exposes the registered gRPC services via HTTP. ```APIDOC ## ServeHTTP ### Description Implements http.Handler, allowing the server to be attached to an *http.Server to expose registered services to HTTP clients. ### Parameters #### Request Body - **w** (http.ResponseWriter) - Required - The HTTP response writer. - **r** (*http.Request) - Required - The incoming HTTP request. ``` -------------------------------- ### Register Service with HandlerMap Source: https://pkg.go.dev/github.com/fullstorydev/grpchan RegisterService registers the given handler to be used for the given service. Only a single handler can be registered for a given service. And services are identified by their fully-qualified name (e.g. "package.name.Service"). ```go func (m HandlerMap) RegisterService(desc *grpc.ServiceDesc, h interface{}) ``` -------------------------------- ### Create Metadata Map Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Constructs a new metadata.MD from a map of string slices. This is useful for setting or inspecting gRPC metadata. ```go func MetadataNew(m map[string][]byte) metadata.MD ``` -------------------------------- ### Create Streaming RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Sends a streaming RPC via the in-process channel. ```go func (ch *Channel) NewStream(ctx context.Context, desc *grpc.StreamDesc, methodName string, opts ...grpc.CallOption) (grpc.ClientStream, error) ``` -------------------------------- ### UnimplementedTestServiceServer BidiStream Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Default implementation for BidiStream, part of UnimplementedTestServiceServer. ```go func (UnimplementedTestServiceServer) BidiStream(TestService_BidiStreamServer) error ``` -------------------------------- ### TestService_BidiStreamServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Server-side interface for bidirectional streaming in TestService. ```go type TestService_BidiStreamServer interface { Send(*Message) error Recv() (*Message, error) grpc.ServerStream } ``` -------------------------------- ### Client Constructors Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Functions to create new clients for the TestService. NewTestServiceChannelClient is deprecated. ```APIDOC ## Client Constructors ### `NewTestServiceChannelClient` ```go func NewTestServiceChannelClient(ch grpc.ClientConnInterface) TestServiceClient ``` **Deprecated:** Use `NewTestServiceClient` instead. ### `NewTestServiceClient` ```go func NewTestServiceClient(cc grpc.ClientConnInterface) TestServiceClient ``` Creates a new TestServiceClient. ``` -------------------------------- ### Configure Base Path Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc WithBasePath configures the gRPC-over-HTTP server to use a specific base path. The default is '/'. This is useful if the server is mounted at a sub-path. ```go func WithBasePath(path string) ServerOption ``` -------------------------------- ### UnimplementedTestServiceServer ClientStream Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Default implementation for ClientStream, part of UnimplementedTestServiceServer. ```go func (UnimplementedTestServiceServer) ClientStream(TestService_ClientStreamServer) error ``` -------------------------------- ### Server Option Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc ServerOption is an interface used for configuring a NewServer. It allows for customization of server behavior. ```go type ServerOption interface { // contains filtered or unexported methods } ``` -------------------------------- ### HttpTrailer Methods Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Methods for interacting with the HttpTrailer structure. ```go func (*HttpTrailer) Descriptor() ([]byte, []int) ``` ```go func (x *HttpTrailer) GetCode() int32 ``` ```go func (x *HttpTrailer) GetDetails() []*anypb.Any ``` ```go func (x *HttpTrailer) GetMessage() string ``` ```go func (x *HttpTrailer) GetMetadata() map[string]*TrailerValues ``` ```go func (*HttpTrailer) ProtoMessage() ``` ```go func (x *HttpTrailer) ProtoReflect() protoreflect.Message ``` ```go func (x *HttpTrailer) Reset() ``` ```go func (x *HttpTrailer) String() string ``` -------------------------------- ### TestServer Implementation Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Provides default implementations for the TestServiceServer interface. ```APIDOC ## TestServer ### Description TestServer has default responses to the various kinds of methods in the TestService. ### Methods - **BidiStream(str TestService_BidiStreamServer) error**: Implements the BidiStream RPC method. - **ClientStream(cs TestService_ClientStreamServer) error**: Implements the ClientStream RPC method. - **ServerStream(req *Message, ss TestService_ServerStreamServer) error**: Implements the ServerStream RPC method. - **Unary(ctx context.Context, req *Message) (*Message, error)**: Implements the Unary RPC method. - **UseExternalMessageTwice(ctx context.Context, in *empty.Empty) (*empty.Empty, error)**: Implements the UseExternalMessageTwice RPC method. ``` -------------------------------- ### Create HTTP Handler for Streaming RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Returns an HTTP handler that dispatches a streaming RPC method to the given server. ```go func HandleStream(svr interface{}, serviceName string, desc *grpc.StreamDesc, streamInt grpc.StreamServerInterceptor, opts ...HandlerOption) http.HandlerFunc ``` -------------------------------- ### Define Handler Option Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Customizes HTTP handler behavior, such as rendering gRPC errors. ```go type HandlerOption func(*handlerOpts) ``` -------------------------------- ### ApplyPerRPCCreds Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Applies per-RPC credentials to a context. Returns a new context with additional metadata or an error if channel security requirements are not met. ```APIDOC ## ApplyPerRPCCreds ### Description Applies any per-RPC credentials in the given call options and returns a new context with the additional metadata. It will return an error if isChannelSecure is false but the per-RPC credentials require a secure channel. ### Method func ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (context.Context, error) - context.Context: A new context with applied credentials. - error: An error if channel security requirements are not met. #### Response Example None ``` -------------------------------- ### String Representation Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc String returns a string representation of the TrailerValues. ```go func (x *TrailerValues) String() string ``` -------------------------------- ### Iterate Over Registered Handlers Source: https://pkg.go.dev/github.com/fullstorydev/grpchan ForEach calls the given function for each registered handler. The function is provided the service description, and the handler. This can be used to contribute all registered handlers to a server and means that applications can easily expose the same services and handlers via multiple channels after registering the handlers once, with the map. ```go func (m HandlerMap) ForEach(fn func(desc *grpc.ServiceDesc, svr interface{})) ``` ```go // Register all handlers once with the map: reg := channel.HandlerMap{} // (these registration functions are generated) foo.RegisterHandlerFooBar(newFooBarImpl()) fu.RegisterHandlerFuBaz(newFuBazImpl()) // Now we can re-use these handlers for multiple channels: // Normal gRPC svr := grpc.NewServer() reg.ForEach(svr.RegisterService) // In-process ipch := &inprocgrpc.Channel{} reg.ForEach(ipch.RegisterService) // And HTTP 1.1 httpgrpc.HandleServices(http.HandleFunc, "/rpc/", reg, nil, nil) ``` -------------------------------- ### RegisterService Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Registers a gRPC service implementation with the server. ```APIDOC ## RegisterService ### Description Registers the given service and implementation. Only a single implementation is allowed for a particular service, identified by its fully-qualified name. ### Parameters #### Request Body - **desc** (*grpc.ServiceDesc) - Required - The service descriptor. - **svr** (interface{}) - Required - The service implementation instance. ``` -------------------------------- ### TestService_BidiStreamClient Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Client-side interface for bidirectional streaming in TestService. ```go type TestService_BidiStreamClient interface { Send(*Message) error Recv() (*Message, error) grpc.ClientStream } ``` -------------------------------- ### TestService_ClientStreamServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Server-side interface for client-side streaming in TestService. ```go type TestService_ClientStreamServer interface { SendAndClose(*Message) error Recv() (*Message, error) grpc.ServerStream } ``` -------------------------------- ### ProtoReflect Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc ProtoReflect returns the message's reflection descriptor. Added in v1.1.0. ```go func (x *TrailerValues) ProtoReflect() protoreflect.Message ``` -------------------------------- ### Set Trailer via ServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal SetTrailer satisfies the grpc.ServerTransportStream and delegates to the underlying grpc.ServerStream. It attempts to use TrySetTrailer if available, otherwise uses the normal SetTrailer. ```go func (sts *ServerTransportStream) SetTrailer(md metadata.MD) error ``` -------------------------------- ### Channel Test Cases Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Utility function to run comprehensive test cases for gRPC channels. ```APIDOC ## RunChannelTestCases ### Description Runs numerous test cases to exercise the behavior of the given channel. The server side of the channel needs to have a *TestServer registered to provide the implementation of fsgrpc.TestService. If the channel does not support full-duplex communication, it must provide at least half-duplex support for bidirectional streams. The test cases will be defined as child tests by invoking t.Run on the given *testing.T. ### Method func ### Endpoint N/A ### Parameters - **t** (*testing.T) - The testing object. - **ch** (grpc.ClientConnInterface) - The gRPC client connection interface. - **supportsFullDuplex** (bool) - Indicates if the channel supports full-duplex communication. ### Request Body N/A ### Response N/A ``` -------------------------------- ### CallOptions Management Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Utilities for converting and managing gRPC call options. ```APIDOC ## GetCallOptions ### Description Converts a slice of grpc.CallOption into a CallOptions struct. ### Parameters - **opts** ([]grpc.CallOption) - Required - The slice of gRPC call options to convert. ## SetHeaders ### Description Sets all accumulated header addresses to the given metadata. ### Parameters - **md** (metadata.MD) - Required - The metadata to set as headers. ## SetPeer ### Description Sets all accumulated peer addresses to the given peer. ### Parameters - **p** (*peer.Peer) - Required - The peer information to set. ## SetTrailers ### Description Sets all accumulated trailer addresses to the given metadata. ### Parameters - **md** (metadata.MD) - Required - The metadata to set as trailers. ``` -------------------------------- ### UnimplementedTestServiceServer Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Base struct for implementing TestServiceServer, ensuring forward compatibility. ```APIDOC ## UnimplementedTestServiceServer ### `UnimplementedTestServiceServer` ```go type UnimplementedTestServiceServer struct { } ``` UnimplementedTestServiceServer must be embedded to have forward compatible implementations. ### Implemented Methods #### `BidiStream` ```go func (UnimplementedTestServiceServer) BidiStream(TestService_BidiStreamServer) error ``` #### `ClientStream` ```go func (UnimplementedTestServiceServer) ClientStream(TestService_ClientStreamServer) error ``` #### `ServerStream` ```go func (UnimplementedTestServiceServer) ServerStream(*Message, TestService_ServerStreamServer) error ``` #### `Unary` ```go func (UnimplementedTestServiceServer) Unary(context.Context, *Message) (*Message, error) ``` #### `UseExternalMessageTwice` ```go func (UnimplementedTestServiceServer) UseExternalMessageTwice(context.Context, *emptypb.Empty) (*emptypb.Empty, error) ``` ``` -------------------------------- ### Declare File Descriptor Variable Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting This variable holds the file descriptor for the test proto file, used internally by the gRPC system. ```go var File_test_proto protoreflect.FileDescriptor ``` -------------------------------- ### TestService_ServerStreamClient Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Client-side interface for server-side streaming in TestService. ```go type TestService_ServerStreamClient interface { Recv() (*Message, error) grpc.ClientStream } ``` -------------------------------- ### TestService_ServerStreamServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Server-side interface for server-side streaming in TestService. ```go type TestService_ServerStreamServer interface { Send(*Message) error grpc.ServerStream } ``` -------------------------------- ### Set Header via ServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal SetHeader satisfies the grpc.ServerTransportStream and delegates to the underlying grpc.ServerStream. ```go func (sts *ServerTransportStream) SetHeader(md metadata.MD) error ``` -------------------------------- ### MetadataNew Function Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Creates new metadata.MD from a map of byte slices. ```APIDOC ## func MetadataNew ### Description Creates a new `metadata.MD` object from a map where keys and values are byte slices. This is useful for constructing gRPC metadata. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go metadataMap := map[string][]byte{ "content-type": []byte("application/grpc"), "custom-header": []byte("some-value"), } md := grpchantesting.MetadataNew(metadataMap) ``` ### Response #### Success Response (200) - **metadata.MD** - The constructed gRPC metadata. ### Response Example ```go // The returned metadata.MD object would represent: // { // "content-type": ["application/grpc"], // "custom-header": ["some-value"] // } ``` ``` -------------------------------- ### Set Headers for CallOptions Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Use SetHeaders to set accumulated header addresses to the given metadata. This satisfies grpc.Header call options. ```go func (co *CallOptions) SetHeaders(md metadata.MD) ``` -------------------------------- ### Convert grpc.CallOption to CallOptions Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Use GetCallOptions to convert a slice of grpc.CallOptions into a CallOptions struct for easier management. ```go func GetCallOptions(opts []grpc.CallOption) *CallOptions ``` -------------------------------- ### Configure Error Renderer Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Returns a HandlerOption to use a custom function for rendering unary RPC errors. ```go func ErrorRenderer(errFunc func(reqCtx context.Context, st *status.Status, response http.ResponseWriter)) HandlerOption ``` -------------------------------- ### Define TestService Service Description Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting This struct defines the gRPC TestService, including its methods and stream types. It is intended for direct use with grpc.RegisterService. ```go var TestService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "grpchantesting.TestService", HandlerType: (*TestServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Unary", Handler: _TestService_Unary_Handler, }, { MethodName: "UseExternalMessageTwice", Handler: _TestService_UseExternalMessageTwice_Handler, }, }, Streams: []grpc.StreamDesc{ { StreamName: "ClientStream", Handler: _TestService_ClientStream_Handler, ClientStreams: true, }, { StreamName: "ServerStream", Handler: _TestService_ServerStream_Handler, ServerStreams: true, }, { StreamName: "BidiStream", Handler: _TestService_BidiStream_Handler, ServerStreams: true, ClientStreams: true, }, }, Metadata: "test.proto", } ``` -------------------------------- ### Define Server Type Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Server is a gRPC-over-HTTP server. It acts as a grpc.ServiceRegistrar for registering server implementations and also implements http.Handler for exposing services via HTTP. ```go type Server struct { // contains filtered or unexported fields } ``` -------------------------------- ### UnimplementedTestServiceServer Unary Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Default implementation for Unary, part of UnimplementedTestServiceServer. ```go func (UnimplementedTestServiceServer) Unary(context.Context, *Message) (*Message, error) ``` -------------------------------- ### Handle Unary RPC Methods Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Creates an HTTP handler function to dispatch unary RPC methods to a gRPC server implementation. ```go func HandleMethod(svr interface{}, serviceName string, desc *grpc.MethodDesc, unaryInt grpc.UnaryServerInterceptor, opts ...HandlerOption) http.HandlerFunc ``` -------------------------------- ### TestService_ClientStreamClient Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Client-side interface for client-side streaming in TestService. ```go type TestService_ClientStreamClient interface { Send(*Message) error CloseAndRecv() (*Message, error) grpc.ClientStream } ``` -------------------------------- ### GetServiceInfo Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Retrieves information about registered services. ```APIDOC ## GetServiceInfo ### Description Returns information about the registered services, enabling the channel to implement the reflection.GRPCServer interface. ### Response #### Success Response (200) - **map[string]grpc.ServiceInfo** - A map of service names to their respective service information. ``` -------------------------------- ### Configure Streaming Interceptor Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc WithServerStreamInterceptor configures the gRPC-over-HTTP server to use the provided interceptor for streaming RPCs during dispatch. ```go func WithServerStreamInterceptor(interceptor grpc.StreamServerInterceptor) ServerOption ``` -------------------------------- ### Deprecated Test Service Channel Client Constructor Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting This constructor is deprecated and should be replaced with NewTestServiceClient. ```go func NewTestServiceChannelClient(ch grpc.ClientConnInterface) TestServiceClient ``` -------------------------------- ### Standard gRPC server registration signature Source: https://pkg.go.dev/github.com/fullstorydev/grpchan The signature of server registration functions generated by older versions of the standard Go gRPC plugin. ```go // A function with this signature is generated, for registering // server handlers with the given server. func RegisterServer(s *grpc.Server, srv Server) { s.RegisterService(&__serviceDesc, srv) } ``` -------------------------------- ### Define HTTP Channel Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Configures a connection for gRPC requests over HTTP 1.1. Both Transport and BaseURL must be specified. ```go type Channel struct { Transport http.RoundTripper BaseURL *url.URL } ``` -------------------------------- ### Set Trailers for CallOptions Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Use SetTrailers to set accumulated trailer addresses to the given metadata. This satisfies grpc.Trailer call options. ```go func (co *CallOptions) SetTrailers(md metadata.MD) ``` -------------------------------- ### UnimplementedTestServiceServer ServerStream Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Default implementation for ServerStream, part of UnimplementedTestServiceServer. ```go func (UnimplementedTestServiceServer) ServerStream(*Message, TestService_ServerStreamServer) error ``` -------------------------------- ### Invoke Unary RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Sends a unary RPC via the in-process channel. ```go func (ch *Channel) Invoke(ctx context.Context, methodName string, req, resp interface{}, opts ...grpc.CallOption) error ``` -------------------------------- ### UnimplementedTestServiceServer UseExternalMessageTwice Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Default implementation for UseExternalMessageTwice, part of UnimplementedTestServiceServer. ```go func (UnimplementedTestServiceServer) UseExternalMessageTwice(context.Context, *emptypb.Empty) (*emptypb.Empty, error) ``` -------------------------------- ### Intercept Server RPCs Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Returns a new service description that will intercepts RPCs with the given interceptors. If both given interceptors are nil, returns svcDesc. ```go func InterceptServer(svcDesc *grpc.ServiceDesc, unaryInt grpc.UnaryServerInterceptor, streamInt grpc.StreamServerInterceptor) *grpc.ServiceDesc ``` -------------------------------- ### Query Service from HandlerMap Source: https://pkg.go.dev/github.com/fullstorydev/grpchan QueryService returns the service descriptor and handler for the named service. If no handler has been registered for the named service, then nil, nil is returned. ```go func (m HandlerMap) QueryService(name string) (*grpc.ServiceDesc, interface{}) ``` -------------------------------- ### TestServiceClient Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Client API definition for the TestService. ```go type TestServiceClient interface { Unary(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) ClientStream(ctx context.Context, opts ...grpc.CallOption) (TestService_ClientStreamClient, error) ServerStream(ctx context.Context, in *Message, opts ...grpc.CallOption) (TestService_ServerStreamClient, error) BidiStream(ctx context.Context, opts ...grpc.CallOption) (TestService_BidiStreamClient, error) // UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in UseExternalMessageTwice(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) } ``` -------------------------------- ### Configure Unary Interceptor Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc WithServerUnaryInterceptor configures the gRPC-over-HTTP server to use the provided interceptor for unary RPCs during dispatch. ```go func WithServerUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) ServerOption ``` -------------------------------- ### Define HTTP Trailer Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Represents the final message in a streaming GRPC-over-HTTP call to encode status and metadata. ```go type HttpTrailer struct { Metadata map[string]*TrailerValues `` /* 157-byte string literal not displayed */ Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"` Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` Details []*anypb.Any `protobuf:"bytes,4,rep,name=details,proto3" json:"details,omitempty"` // contains filtered or unexported fields } ``` -------------------------------- ### HandlerOption Type Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc An option to customize HTTP handler behavior. ```APIDOC ### Type: HandlerOption HandlerOption is an option to customize some aspect of the HTTP handler behavior, such as rendering gRPC errors to HTTP responses. HandlerOptions also implement ServerOption. #### Functions: - **ErrorRenderer(errFunc func(reqCtx context.Context, st *status.Status, response http.ResponseWriter)) HandlerOption**: Returns a HandlerOption that will cause the handler to use the given function to render an error. It is only used for unary RPCs since streaming RPCs serialize a status message to the response trailer (in the HTTP body) instead. The function should call methods on response in order to write an error response, including any response headers, the HTTP status code, and any response body. If no such option is used, the handler will use DefaultErrorRenderer. ``` -------------------------------- ### HandleServices Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Registers handlers for all methods exposed by registered handlers in a given Mux. ```APIDOC ## POST /websites/pkg_go_dev_github_com_fullstorydev_grpchan ### Description HandleServices uses the given mux to register handlers for all methods exposed by handlers registered in reg. They are registered using a path of "basePath/name.of.Service/Method". If non-nil interceptor(s) are provided then they will be used to intercept applicable RPCs before dispatch to the registered handler. ### Method POST ### Endpoint /websites/pkg_go_dev_github_com_fullstorydev_grpchan ### Parameters #### Path Parameters - **mux** (Mux) - Required - The Mux to register handlers with. - **basePath** (string) - Required - The base path for registering handlers. - **reg** (grpchan.HandlerMap) - Required - A map of service names to their handlers. - **unaryInt** (grpc.UnaryServerInterceptor) - Optional - Interceptor for unary RPCs. - **streamInt** (grpc.StreamServerInterceptor) - Optional - Interceptor for streaming RPCs. - **opts** (...HandlerOption) - Optional - Options to customize handler behavior. ``` -------------------------------- ### UnimplementedTestServiceServer Struct Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Embed this struct for forward compatibility in TestServiceServer implementations. ```go type UnimplementedTestServiceServer struct { } ``` -------------------------------- ### grpchan Sub-packages Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Overview of the sub-packages available within the grpchan project, each serving a distinct purpose. ```APIDOC ## grpchan Sub-packages ### cmd/protoc-gen-grpchan **Synopsis**: protoc-gen-grpchan is a protoc plugin that generates gRPC client stubs in Go that use github.com/fullstorydev/grpchan.Channel as their transport abstraction, instead of using *grpc.ClientConn. ### grpchantesting **Synopsis**: Package grpchantesting helps with testing implementations of alternate gRPC transports. ### httpgrpc **Synopsis**: Package httpgrpc contains code for using HTTP 1.1 for GRPC calls. ### inprocgrpc **Synopsis**: Package inprocgrpc provides an in-process gRPC channel implementation. ``` -------------------------------- ### Define Mux Function Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Defines a function signature for registering gRPC-over-HTTP handlers. ```go type Mux func(pattern string, handler func(http.ResponseWriter, *http.Request)) ``` -------------------------------- ### Render Default gRPC Errors Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Translates gRPC status codes into corresponding HTTP error responses. ```go func DefaultErrorRenderer(ctx context.Context, st *status.Status, w http.ResponseWriter) ``` -------------------------------- ### HandleStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Returns an HTTP handler that will handle a streaming RPC method. ```APIDOC ## POST /websites/pkg_go_dev_github_com_fullstorydev_grpchan/stream ### Description HandleStream returns an HTTP handler that will handle a streaming RPC method by dispatching the given method on the given server. ### Method POST ### Endpoint /websites/pkg_go_dev_github_com_fullstorydev_grpchan/stream ### Parameters #### Path Parameters - **svr** (interface{}) - Required - The server implementation. - **serviceName** (string) - Required - The name of the service. - **desc** (*grpc.StreamDesc) - Required - The stream descriptor. - **streamInt** (grpc.StreamServerInterceptor) - Optional - Interceptor for streaming RPCs. - **opts** (...HandlerOption) - Optional - Options to customize handler behavior. ``` -------------------------------- ### Set Peer for CallOptions Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Use SetPeer to set accumulated peer addresses to the given peer. This satisfies grpc.Peer call options. ```go func (co *CallOptions) SetPeer(p *peer.Peer) ``` -------------------------------- ### Channel.Invoke Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Satisfies the grpchan.Channel interface and supports sending unary RPCs. ```APIDOC ## POST /websites/pkg_go_dev_github_com_fullstorydev_grpchan/channel/invoke ### Description Invoke satisfies the grpchan.Channel interface and supports sending unary RPCs via the in-process channel. ### Method POST ### Endpoint /websites/pkg_go_dev_github_com_fullstorydev_grpchan/channel/invoke ### Parameters #### Path Parameters - **ch** (*Channel) - Required - The Channel instance. - **ctx** (context.Context) - Required - The request context. - **methodName** (string) - Required - The name of the method to invoke. - **req** (interface{}) - Required - The request payload. - **resp** (interface{}) - Required - The response payload. - **opts** (...grpc.CallOption) - Optional - Options for the gRPC call. ``` -------------------------------- ### Send Header via ServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal SendHeader satisfies the grpc.ServerTransportStream and delegates to the underlying grpc.ServerStream. ```go func (sts *ServerTransportStream) SendHeader(md metadata.MD) error ``` -------------------------------- ### InterceptServer Source: https://pkg.go.dev/github.com/fullstorydev/grpchan InterceptServer returns a new service description that will intercepts RPCs with the given interceptors. If both given interceptors are nil, returns svcDesc. ```APIDOC ## InterceptServer ### Description Intercepts RPCs with the given interceptors for a service description. ### Method `func InterceptServer(svcDesc *grpc.ServiceDesc, unaryInt grpc.UnaryServerInterceptor, streamInt grpc.StreamServerInterceptor) *grpc.ServiceDesc` ### Parameters - **svcDesc** (*grpc.ServiceDesc) - The service description to intercept. - **unaryInt** (grpc.UnaryServerInterceptor) - The unary server interceptor. - **streamInt** (grpc.StreamServerInterceptor) - The stream server interceptor. ### Returns *grpc.ServiceDesc - A new service description with interceptors applied. ``` -------------------------------- ### Register gRPC Services Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Registers handlers for all methods exposed by the provided service handlers using the specified mux. ```go func HandleServices(mux Mux, basePath string, reg grpchan.HandlerMap, unaryInt grpc.UnaryServerInterceptor, streamInt grpc.StreamServerInterceptor, opts ...HandlerOption) ``` -------------------------------- ### ProtoMessage Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc ProtoMessage is a method required by the protobuf interface. ```go func (*TrailerValues) ProtoMessage() ``` -------------------------------- ### CallOptions Type Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal Represents the state of in-effect gRPC call options, including headers, trailers, peer information, credentials, and message size limits. ```APIDOC ## CallOptions ### Description Represents the state of in-effect grpc.CallOptions. ### Fields - Headers ([]*metadata.MD): Metadata to be set when response header metadata is received. - Trailers ([]*metadata.MD): Metadata to be set when response trailer metadata is received. - Peer ([]*peer.Peer): Peer information to be set when the remote peer is known. - Creds (credentials.PerRPCCredentials): Per-RPC credentials to use for a call. - MaxRecv (int): Maximum number of bytes to receive for a single message. - MaxSend (int): Maximum number of bytes to send for a single message. ### Methods - SetHeaders(md metadata.MD): Sets the call option headers. - SetPeer(p *peer.Peer): Sets the call option peer. - SetTrailers(md metadata.MD): Sets the call option trailers. ### Example Usage ```go // Example of creating and setting CallOptions callOpts := &grpchan.CallOptions{} headers := metadata.Pairs("key", "value") callOpts.SetHeaders(headers) // Use callOpts in a gRPC call // ctx, err := grpchan.ApplyPerRPCCreds(ctx, callOpts, "/my.service.MyService/MyMethod", true) ``` ``` -------------------------------- ### Stream Server Interfaces Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Interfaces for server-side streaming operations of the TestService. ```APIDOC ## Stream Server Interfaces ### `TestService_BidiStreamServer` ```go type TestService_BidiStreamServer interface { Send(*Message) error Recv() (*Message, error) grpc.ServerStream } ``` ### `TestService_ClientStreamServer` ```go type TestService_ClientStreamServer interface { SendAndClose(*Message) error Recv() (*Message, error) grpc.ServerStream } ``` ### `TestService_ServerStreamServer` ```go type TestService_ServerStreamServer interface { Send(*Message) error grpc.ServerStream } ``` ``` -------------------------------- ### Deprecated Descriptor Method Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Deprecated: Use TrailerValues.ProtoReflect.Descriptor instead of this method. ```go func (*TrailerValues) Descriptor() ([]byte, []int) ``` -------------------------------- ### Access File Descriptor Variable Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Variable representing the file descriptor for the httpgrpc protocol buffer definition. ```go var File_httpgrpc_proto protoreflect.FileDescriptor ``` -------------------------------- ### UnsafeTestServiceServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Interface for opting out of forward compatibility in TestServiceServer. Use with caution as it may lead to compilation errors with future service updates. ```go type UnsafeTestServiceServer interface { // contains filtered or unexported methods } ``` -------------------------------- ### TestService BidiStream RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Handles bidirectional-streaming RPC calls for the TestService. ```APIDOC ## POST /grpchantesting.TestService/BidiStream ### Description Handles bidirectional-streaming RPC calls where both the client and server can send a sequence of messages independently. ### Method POST ### Endpoint /grpchantesting.TestService/BidiStream ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stream** (TestService_BidiStreamServer) - Required - A bidirectional stream for sending and receiving messages. ### Request Example ```json { "client_messages": [ {"payload": "client msg 1"}, {"payload": "client msg 2"} ], "server_response_delay_millis": 300 } ``` ### Response #### Success Response (200) - **stream** (TestService_BidiStreamClient) - A bidirectional stream for sending and receiving messages. #### Response Example ```json [ { "payload": "server response 1" }, { "payload": "server response 2" } ] ``` ``` -------------------------------- ### Set Trailer via UnaryServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal SetTrailer satisfies the grpc.ServerTransportStream, adding metadata to the response trailers that will be sent to the client. ```go func (sts *UnaryServerTransportStream) SetTrailer(md metadata.MD) error ``` -------------------------------- ### TestServiceServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting The server API for the TestService. Implementations must embed UnimplementedTestServiceServer for forward compatibility. ```go type TestServiceServer interface { Unary(context.Context, *Message) (*Message, error) ClientStream(TestService_ClientStreamServer) error ServerStream(*Message, TestService_ServerStreamServer) error BidiStream(TestService_BidiStreamServer) error // UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in UseExternalMessageTwice(context.Context, *emptypb.Empty) (*emptypb.Empty, error) // contains filtered or unexported methods } ``` -------------------------------- ### func HandleMethod Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Returns an HTTP handler that dispatches a unary RPC method to the provided gRPC server implementation. ```APIDOC ## HandleMethod ### Description Returns an HTTP handler that will handle a unary RPC method by dispatching the given method on the given server. ### Parameters - **svr** (interface{}) - Required - The gRPC server implementation. - **serviceName** (string) - Required - The name of the service. - **desc** (*grpc.MethodDesc) - Required - The method descriptor. - **unaryInt** (grpc.UnaryServerInterceptor) - Required - The unary server interceptor. - **opts** (...HandlerOption) - Optional - Additional handler options. ``` -------------------------------- ### Message Accessor Methods Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Standard getter and utility methods for the Message struct. ```go func (*Message) Descriptor() ([]byte, []int) ``` ```go func (x *Message) GetCode() int32 ``` ```go func (x *Message) GetCount() int32 ``` ```go func (x *Message) GetDelayMillis() int32 ``` ```go func (x *Message) GetErrorDetails() []*anypb.Any ``` ```go func (x *Message) GetHeaders() map[string][]byte ``` ```go func (x *Message) GetPayload() []byte ``` ```go func (x *Message) GetTrailers() map[string][]byte ``` ```go func (*Message) ProtoMessage() ``` ```go func (x *Message) ProtoReflect() protoreflect.Message ``` ```go func (*Message) Reset() ``` ```go func (x *Message) String() string ``` -------------------------------- ### TestService ClientStream RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Handles client-streaming RPC calls for the TestService. ```APIDOC ## POST /grpchantesting.TestService/ClientStream ### Description Handles client-streaming RPC calls where the client sends a sequence of messages to the server. ### Method POST ### Endpoint /grpchantesting.TestService/ClientStream ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stream** (TestService_ClientStreamServer) - Required - A stream of messages from the client. ### Request Example ```json [ { "payload": "message 1" }, { "payload": "message 2" } ] ``` ### Response #### Success Response (200) - **Message** (Message) - A single response message from the server after receiving all client messages. #### Response Example ```json { "payload": "processed all messages" } ``` ``` -------------------------------- ### TestServiceClient Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Client API for the TestService service. ```APIDOC ## TestServiceClient Interface ### Description TestServiceClient is the client API for the TestService service. For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. ### Methods - **Unary(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error)**: Makes a unary RPC call. - **ClientStream(ctx context.Context, opts ...grpc.CallOption) (TestService_ClientStreamClient, error)**: Initiates a client-streaming RPC call. - **ServerStream(ctx context.Context, in *Message, opts ...grpc.CallOption) (TestService_ServerStreamClient, error)**: Initiates a server-streaming RPC call. - **BidiStream(ctx context.Context, opts ...grpc.CallOption) (TestService_BidiStreamClient, error)**: Initiates a bidirectional-streaming RPC call. - **UseExternalMessageTwice(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)**: A method purely to test the protoc-gen-grpchan plug-in. ``` -------------------------------- ### Define WrappedClientConn interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Interface definition for wrapping gRPC client connections with access to the underlying implementation. ```go type WrappedClientConn interface { grpc.ClientConnInterface Unwrap() grpc.ClientConnInterface } ``` -------------------------------- ### Stream Client Interfaces Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Interfaces for client-side streaming operations of the TestService. ```APIDOC ## Stream Client Interfaces ### `TestService_BidiStreamClient` ```go type TestService_BidiStreamClient interface { Send(*Message) error Recv() (*Message, error) grpc.ClientStream } ``` ### `TestService_ClientStreamClient` ```go type TestService_ClientStreamClient interface { Send(*Message) error CloseAndRecv() (*Message, error) grpc.ClientStream } ``` ### `TestService_ServerStreamClient` ```go type TestService_ServerStreamClient interface { Recv() (*Message, error) grpc.ClientStream } ``` ``` -------------------------------- ### UnsafeTestServiceServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Interface for opting out of forward compatibility for TestServiceServer. ```APIDOC ## UnsafeTestServiceServer Interface ### `UnsafeTestServiceServer` ```go interface { // contains filtered or unexported methods } ``` UnsafeTestServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to TestServiceServer will result in compilation errors. ``` -------------------------------- ### Intercept Client Connections with InterceptClientConn Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Returns a new channel that intercepts RPCs with the given unary and stream interceptors. If both interceptors are nil, the original channel is returned. ```go func InterceptClientConn(ch grpc.ClientConnInterface, unaryInt grpc.UnaryClientInterceptor, streamInt grpc.StreamClientInterceptor) grpc.ClientConnInterface ``` -------------------------------- ### Intercept Streaming RPCs with InterceptClientConnStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Returns a new channel that intercepts streaming RPCs using a chain of interceptors. The first interceptor in the provided set is invoked first. ```go func InterceptClientConnStream(ch grpc.ClientConnInterface, streamInt ...grpc.StreamClientInterceptor) grpc.ClientConnInterface ``` -------------------------------- ### Set Header via UnaryServerTransportStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/internal SetHeader satisfies the grpc.ServerTransportStream, adding metadata to the response headers that will be sent to the client. ```go func (sts *UnaryServerTransportStream) SetHeader(md metadata.MD) error ``` -------------------------------- ### Channel.NewStream Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/httpgrpc Satisfies the grpchan.Channel interface and supports sending streaming RPCs. ```APIDOC ## POST /websites/pkg_go_dev_github_com_fullstorydev_grpchan/channel/newstream ### Description NewStream satisfies the grpchan.Channel interface and supports sending streaming RPCs via the in-process channel. ### Method POST ### Endpoint /websites/pkg_go_dev_github_com_fullstorydev_grpchan/channel/newstream ### Parameters #### Path Parameters - **ch** (*Channel) - Required - The Channel instance. - **ctx** (context.Context) - Required - The request context. - **desc** (*grpc.StreamDesc) - Required - The stream descriptor. - **methodName** (string) - Required - The name of the method to invoke. - **opts** (...grpc.CallOption) - Optional - Options for the gRPC call. ``` -------------------------------- ### Apply Unary Interceptors to Registered Services Source: https://pkg.go.dev/github.com/fullstorydev/grpchan Returns a view of the given ServiceRegistrar that will automatically apply the given interceptors to all registered services. ```go func WithUnaryInterceptors(reg grpc.ServiceRegistrar, unaryInt ...grpc.UnaryServerInterceptor) grpc.ServiceRegistrar ``` -------------------------------- ### TestServiceServer Interface Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Defines the server-side interface for the TestService. ```APIDOC ## TestServiceServer Interface ### `TestServiceServer` ```go type TestServiceServer interface { Unary(context.Context, *Message) (*Message, error) ClientStream(TestService_ClientStreamServer) error ServerStream(*Message, TestService_ServerStreamServer) error BidiStream(TestService_BidiStreamServer) error // UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in UseExternalMessageTwice(context.Context, *emptypb.Empty) (*emptypb.Empty, error) // contains filtered or unexported methods } ``` TestServiceServer is the server API for TestService service. All implementations must embed UnimplementedTestServiceServer for forward compatibility. ``` -------------------------------- ### TestService Unary RPC Source: https://pkg.go.dev/github.com/fullstorydev/grpchan/grpchantesting Handles unary RPC calls for the TestService. ```APIDOC ## POST /grpchantesting.TestService/Unary ### Description Handles unary RPC calls for the TestService. This method is used for simple request-response interactions. ### Method POST ### Endpoint /grpchantesting.TestService/Unary ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **req** (Message) - Required - The request message containing payload, headers, and other details. ### Request Example ```json { "payload": "SGVsbG8gV29ybGQh", "headers": { "content-type": "application/grpc" }, "delay_millis": 100 } ``` ### Response #### Success Response (200) - **Message** (Message) - The response message, potentially containing payload, headers, and trailers. #### Response Example ```json { "payload": "SGVsbG8gZnJvbSBzZXJ2ZXIh", "headers": { "x-custom-header": "response-value" }, "trailers": { "grpc-status": "0" } } ``` ```