Documentation ¶
Overview ¶
grpcConst is a package that allow you to communicate defaulting values of your protobuf messages and communicate this default and set it before your client side code interacts with the messages. example server-side:
header, err := grpcConst.HeaderSetConstant( &proto.Feature{ Name: "some constant name", Location: &proto.Point{Latitude: 10} }) stream.SetHeader(header) ... your normal routine but you could ... fx send &proto.Feature{Location: &proto.Point{Longitude: 20}} ... this will yield - name: "some constant name", location: {10, 20} ... while sending less data in the message
or:
stream = grpcConst.ServerStreMWrapper( &proto.Feature{ Name: "some constant name", Location: &proto.Point{Latitude: 10} }) ... using stream.Send() now removes the default values from your objects; sending less data
example client-side: initiate your client with a grpc.StreamClientInterceptor this way:
conn, err := grpc.Dial(..., grpc.WithStreamInterceptor(grpcConst.StreamClientInterceptor()))
Index ¶
- Constants
- func HeaderSetConstant(v interface{}) (metadata.MD, error)
- func ServerStreamWrapper(reference interface{}) (stream grpc.ServerStream, err error)
- func StreamClientInterceptor(mergerCreator ...MergerCreator) grpc.StreamClientInterceptor
- type Merger
- type MergerCreator
- type MessageMergerReducer
- type Reducer
Constants ¶
const XgRPCConst = "x-grpc-const"
XgRPCConst is the HTTP header passed between server and client
Variables ¶
This section is empty.
Functions ¶
func HeaderSetConstant ¶
HeaderSetConstant is a convenience method for the server side to add a metadata.MD with the correct content given your gRPC struct v, the user is returned the metadata to send. that the user can send using `grpc.ServerStream:SendHeader(metadata.MD) or :SetHeader(metadata.MD)`. v must be passed by reference.
func ServerStreamWrapper ¶
func ServerStreamWrapper(reference interface{}) (stream grpc.ServerStream, err error)
ServerStreamWrapper wraps your stream object and returns the decorated stream with a SendMsg method, that removes items that are equal a reference object. The stream remains untouched if the client did not send an XgRPCConst header
func StreamClientInterceptor ¶
func StreamClientInterceptor(mergerCreator ...MergerCreator) grpc.StreamClientInterceptor
StreamClientInterceptor is an interceptor for the client side (for unidirectional server-side streaming rpc's) The client side Stream interceptor intercepts the stream when it is initiated. This method decorates the actual ClientStream adding data to each message where applicable this variadic function accepts none or one argument. defaulting the method for constructing the merge.Merger to use merge.NewMerger. for a more safe alternative
Types ¶
type Merger ¶
type Merger interface {
Merge(interface{})
}
Merger is the interface of a type that can merge into itself
type MergerCreator ¶
MergerCreator is a proxy for a function returning a merge.Merger from an interface{}
type MessageMergerReducer ¶
type MessageMergerReducer struct {
ConstantMessage interface{}
}
func (MessageMergerReducer) RemoveFields ¶
func (m MessageMergerReducer) RemoveFields(msg interface{}) error
func (MessageMergerReducer) SetFields ¶
func (m MessageMergerReducer) SetFields(msg interface{}) error
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
merge is a package with support functionality for grpcConst this helps add default values from one object to many objects the code skips a lot of reflection because much can be assumed at initiation There may be some issues with this package, it is meant for mapping structs compiled via protoc/gRPC.
|
merge is a package with support functionality for grpcConst this helps add default values from one object to many objects the code skips a lot of reflection because much can be assumed at initiation There may be some issues with this package, it is meant for mapping structs compiled via protoc/gRPC. |