Documentation ¶
Index ¶
- Constants
- Variables
- func CodeFromHTTPStatus(httpStatusCode int) codes.Code
- func ErrorFromHTTPResponseCode(code int, detail string) error
- func ErrorFromInternalStatus(internalStatus *internalv1pb.Status) error
- func HTTPStatusFromCode(code codes.Code) int
- func InternalMetadataToGrpcMetadata(ctx context.Context, internalMD DaprInternalMetadata, ...) metadata.MD
- func InternalMetadataToHTTPHeader(ctx context.Context, internalMD DaprInternalMetadata, ...)
- func IsGRPCProtocol(internalMD DaprInternalMetadata) bool
- func IsJSONContentType(contentType string) bool
- func ProtobufToJSON(message protoreflect.ProtoMessage) ([]byte, error)
- func ReservedGRPCMetadataToDaprPrefixHeader(key string) string
- func WithCustomGRPCMetadata(ctx context.Context, md map[string]string) context.Context
- type DaprInternalMetadata
- type DirectMessaging
- type InvokeMethodRequest
- func (imr *InvokeMethodRequest) APIVersion() internalv1pb.APIVersion
- func (imr *InvokeMethodRequest) Actor() *internalv1pb.Actor
- func (imr *InvokeMethodRequest) AddMetadata(md map[string][]string)
- func (imr *InvokeMethodRequest) CanReplay() bool
- func (rr *InvokeMethodRequest) Close() (err error)
- func (imr *InvokeMethodRequest) ContentType() string
- func (imr *InvokeMethodRequest) EncodeHTTPQueryString() string
- func (imr *InvokeMethodRequest) GetDataObject() any
- func (imr *InvokeMethodRequest) HasMessageData() bool
- func (imr *InvokeMethodRequest) Message() *commonv1pb.InvokeRequest
- func (imr *InvokeMethodRequest) Metadata() DaprInternalMetadata
- func (imr *InvokeMethodRequest) Proto() *internalv1pb.InternalInvokeRequest
- func (imr *InvokeMethodRequest) ProtoWithData() (*internalv1pb.InternalInvokeRequest, error)
- func (imr *InvokeMethodRequest) RawData() (r io.Reader)
- func (imr *InvokeMethodRequest) RawDataFull() ([]byte, error)
- func (imr *InvokeMethodRequest) ResetMessageData()
- func (rr *InvokeMethodRequest) SetReplay(enabled bool)
- func (imr *InvokeMethodRequest) WithActor(actorType, actorID string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithContentType(contentType string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithCustomHTTPMetadata(md map[string]string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithDataObject(data any) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithDataTypeURL(val string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithFastHTTPHeaders(header *fasthttp.RequestHeader) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithHTTPExtension(verb string, querystring string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithHTTPHeaders(header http.Header) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithMetadata(md map[string][]string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithRawData(data io.Reader) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithRawDataBytes(data []byte) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithRawDataString(data string) *InvokeMethodRequest
- func (imr *InvokeMethodRequest) WithReplay(enabled bool) *InvokeMethodRequest
- type InvokeMethodResponse
- func (imr *InvokeMethodResponse) CanReplay() bool
- func (rr *InvokeMethodResponse) Close() (err error)
- func (imr *InvokeMethodResponse) ContentType() string
- func (imr *InvokeMethodResponse) HasMessageData() bool
- func (imr *InvokeMethodResponse) Headers() DaprInternalMetadata
- func (imr *InvokeMethodResponse) IsHTTPResponse() bool
- func (imr *InvokeMethodResponse) Message() *commonv1pb.InvokeResponse
- func (imr *InvokeMethodResponse) Proto() *internalv1pb.InternalInvokeResponse
- func (imr *InvokeMethodResponse) ProtoWithData() (*internalv1pb.InternalInvokeResponse, error)
- func (imr *InvokeMethodResponse) RawData() (r io.Reader)
- func (imr *InvokeMethodResponse) RawDataFull() ([]byte, error)
- func (imr *InvokeMethodResponse) ResetMessageData()
- func (rr *InvokeMethodResponse) SetReplay(enabled bool)
- func (imr *InvokeMethodResponse) Status() *internalv1pb.Status
- func (imr *InvokeMethodResponse) Trailers() DaprInternalMetadata
- func (imr *InvokeMethodResponse) WithContentType(contentType string) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithDataTypeURL(val string) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithFastHTTPHeaders(header *fasthttp.ResponseHeader) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithHTTPHeaders(headers map[string][]string) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithHeaders(headers metadata.MD) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithMessage(pb *commonv1pb.InvokeResponse) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithRawData(data io.Reader) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithRawDataBytes(data []byte) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithRawDataString(data string) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithReplay(enabled bool) *InvokeMethodResponse
- func (imr *InvokeMethodResponse) WithTrailers(trailer metadata.MD) *InvokeMethodResponse
Constants ¶
const ( // Maximum size, in bytes, for the buffer used by CallLocalStream: 2KB. StreamBufferSize = 2 << 10 // GRPCContentType is the MIME media type for grpc. GRPCContentType = "application/grpc" // JSONContentType is the MIME media type for JSON. JSONContentType = "application/json" // ProtobufContentType is the MIME media type for Protobuf. ProtobufContentType = "application/x-protobuf" // OctetStreamContentType is the MIME media type for arbitrary binary data. OctetStreamContentType = "application/octet-stream" // ContentTypeHeader is the header key of content-type. ContentTypeHeader = "content-type" // ContentLengthHeader is the header key of content-length. ContentLengthHeader = "content-length" // DaprHeaderPrefix is the prefix if metadata is defined by non user-defined http headers. DaprHeaderPrefix = "dapr-" // DestinationIDHeader is the header carrying the value of the invoked app id. DestinationIDHeader = "destination-app-id" CallerIDHeader = DaprHeaderPrefix + "caller-app-id" CalleeIDHeader = DaprHeaderPrefix + "callee-app-id" )
const ( // DefaultAPIVersion is the default Dapr API version. DefaultAPIVersion = internalv1pb.APIVersion_V1 //nolint:nosnakecase )
Variables ¶
var BufPool = sync.Pool{ New: func() any { b := make([]byte, StreamBufferSize) return &b }, }
BufPool is a pool of *[]byte used by direct messaging (for sending on both the server and client). Their size is fixed at StreamBufferSize.
Functions ¶
func CodeFromHTTPStatus ¶
CodeFromHTTPStatus converts http status code to gRPC status code See: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
func ErrorFromHTTPResponseCode ¶
ErrorFromHTTPResponseCode converts http response code to gRPC status error.
func ErrorFromInternalStatus ¶
func ErrorFromInternalStatus(internalStatus *internalv1pb.Status) error
ErrorFromInternalStatus converts internal status to gRPC status error.
func HTTPStatusFromCode ¶
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L15 See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func InternalMetadataToGrpcMetadata ¶
func InternalMetadataToGrpcMetadata(ctx context.Context, internalMD DaprInternalMetadata, httpHeaderConversion bool) metadata.MD
InternalMetadataToGrpcMetadata converts internal metadata map to gRPC metadata.
func InternalMetadataToHTTPHeader ¶
func InternalMetadataToHTTPHeader(ctx context.Context, internalMD DaprInternalMetadata, setHeader func(string, string))
InternalMetadataToHTTPHeader converts internal metadata pb to HTTP headers.
func IsGRPCProtocol ¶
func IsGRPCProtocol(internalMD DaprInternalMetadata) bool
IsGRPCProtocol checks if metadata is originated from gRPC API.
func IsJSONContentType ¶
IsJSONContentType returns true if contentType is the mime media type for JSON.
func ProtobufToJSON ¶
func ProtobufToJSON(message protoreflect.ProtoMessage) ([]byte, error)
ProtobufToJSON serializes Protobuf message to json format.
Types ¶
type DaprInternalMetadata ¶
type DaprInternalMetadata map[string]*internalv1pb.ListStringValue
DaprInternalMetadata is the metadata type to transfer HTTP header and gRPC metadata from user app to Dapr.
type DirectMessaging ¶
type DirectMessaging interface {
Invoke(ctx context.Context, targetAppID string, req *InvokeMethodRequest) (*InvokeMethodResponse, error)
}
DirectMessaging is the API interface for invoking a remote app.
type InvokeMethodRequest ¶
type InvokeMethodRequest struct {
// contains filtered or unexported fields
}
InvokeMethodRequest holds InternalInvokeRequest protobuf message and provides the helpers to manage it.
func FromInternalInvokeRequest ¶
func FromInternalInvokeRequest(pb *internalv1pb.InternalInvokeRequest) (*InvokeMethodRequest, error)
FromInternalInvokeRequest creates InvokeMethodRequest object from FromInternalInvokeRequest pb object.
func FromInvokeRequestMessage ¶
func FromInvokeRequestMessage(pb *commonv1pb.InvokeRequest) *InvokeMethodRequest
FromInvokeRequestMessage creates InvokeMethodRequest object from InvokeRequest pb object.
func NewInvokeMethodRequest ¶
func NewInvokeMethodRequest(method string) *InvokeMethodRequest
NewInvokeMethodRequest creates InvokeMethodRequest object for method.
func (*InvokeMethodRequest) APIVersion ¶
func (imr *InvokeMethodRequest) APIVersion() internalv1pb.APIVersion
APIVersion gets API version of InvokeMethodRequest.
func (*InvokeMethodRequest) Actor ¶
func (imr *InvokeMethodRequest) Actor() *internalv1pb.Actor
Actor returns actor type and id.
func (*InvokeMethodRequest) AddMetadata ¶
func (imr *InvokeMethodRequest) AddMetadata(md map[string][]string)
AddMetadata adds new metadata options to the existing set.
func (*InvokeMethodRequest) CanReplay ¶
func (imr *InvokeMethodRequest) CanReplay() bool
CanReplay returns true if the data stream can be replayed.
func (*InvokeMethodRequest) Close ¶
func (rr *InvokeMethodRequest) Close() (err error)
Close the data stream and replay buffers. It's safe to call Close multiple times on the same object.
func (*InvokeMethodRequest) ContentType ¶
func (imr *InvokeMethodRequest) ContentType() string
ContentType returns the content type of the message.
func (*InvokeMethodRequest) EncodeHTTPQueryString ¶
func (imr *InvokeMethodRequest) EncodeHTTPQueryString() string
EncodeHTTPQueryString generates querystring for http using http extension object.
func (*InvokeMethodRequest) GetDataObject ¶
func (imr *InvokeMethodRequest) GetDataObject() any
GetDataObject returns the data object stored in the object
func (*InvokeMethodRequest) HasMessageData ¶
func (imr *InvokeMethodRequest) HasMessageData() bool
HasMessageData returns true if the message object contains a slice of data buffered.
func (*InvokeMethodRequest) Message ¶
func (imr *InvokeMethodRequest) Message() *commonv1pb.InvokeRequest
Message gets InvokeRequest Message object.
func (*InvokeMethodRequest) Metadata ¶
func (imr *InvokeMethodRequest) Metadata() DaprInternalMetadata
Metadata gets Metadata of InvokeMethodRequest.
func (*InvokeMethodRequest) Proto ¶
func (imr *InvokeMethodRequest) Proto() *internalv1pb.InternalInvokeRequest
Proto returns InternalInvokeRequest Proto object.
func (*InvokeMethodRequest) ProtoWithData ¶
func (imr *InvokeMethodRequest) ProtoWithData() (*internalv1pb.InternalInvokeRequest, error)
ProtoWithData returns a copy of the internal InternalInvokeRequest Proto object with the entire data stream read into the Data property.
func (*InvokeMethodRequest) RawData ¶
func (imr *InvokeMethodRequest) RawData() (r io.Reader)
RawData returns the stream body. Note: this method is not safe for concurrent use.
func (*InvokeMethodRequest) RawDataFull ¶
func (imr *InvokeMethodRequest) RawDataFull() ([]byte, error)
RawDataFull returns the entire data read from the stream body.
func (*InvokeMethodRequest) ResetMessageData ¶
func (imr *InvokeMethodRequest) ResetMessageData()
ResetMessageData resets the data inside the message object if present.
func (*InvokeMethodRequest) SetReplay ¶
func (rr *InvokeMethodRequest) SetReplay(enabled bool)
SetReplay enables replaying for the data stream.
func (*InvokeMethodRequest) WithActor ¶
func (imr *InvokeMethodRequest) WithActor(actorType, actorID string) *InvokeMethodRequest
WithActor sets actor type and id.
func (*InvokeMethodRequest) WithContentType ¶
func (imr *InvokeMethodRequest) WithContentType(contentType string) *InvokeMethodRequest
WithContentType sets the content type.
func (*InvokeMethodRequest) WithCustomHTTPMetadata ¶
func (imr *InvokeMethodRequest) WithCustomHTTPMetadata(md map[string]string) *InvokeMethodRequest
WithCustomHTTPMetadata applies a metadata map to a InvokeMethodRequest.
func (*InvokeMethodRequest) WithDataObject ¶
func (imr *InvokeMethodRequest) WithDataObject(data any) *InvokeMethodRequest
WithDataObject sets message from an object which will be serialized as JSON
func (*InvokeMethodRequest) WithDataTypeURL ¶
func (imr *InvokeMethodRequest) WithDataTypeURL(val string) *InvokeMethodRequest
WithDataTypeURL sets the type_url property for the data. When a type_url is set, the Content-Type automatically becomes the protobuf one.
func (*InvokeMethodRequest) WithFastHTTPHeaders ¶
func (imr *InvokeMethodRequest) WithFastHTTPHeaders(header *fasthttp.RequestHeader) *InvokeMethodRequest
WithFastHTTPHeaders sets metadata from fasthttp request headers.
func (*InvokeMethodRequest) WithHTTPExtension ¶
func (imr *InvokeMethodRequest) WithHTTPExtension(verb string, querystring string) *InvokeMethodRequest
WithHTTPExtension sets new HTTP extension with verb and querystring.
func (*InvokeMethodRequest) WithHTTPHeaders ¶
func (imr *InvokeMethodRequest) WithHTTPHeaders(header http.Header) *InvokeMethodRequest
WithHTTPHeaders sets metadata from HTTP request headers.
func (*InvokeMethodRequest) WithMetadata ¶
func (imr *InvokeMethodRequest) WithMetadata(md map[string][]string) *InvokeMethodRequest
WithMetadata sets metadata.
func (*InvokeMethodRequest) WithRawData ¶
func (imr *InvokeMethodRequest) WithRawData(data io.Reader) *InvokeMethodRequest
WithRawData sets message data from a readable stream.
func (*InvokeMethodRequest) WithRawDataBytes ¶
func (imr *InvokeMethodRequest) WithRawDataBytes(data []byte) *InvokeMethodRequest
WithRawDataBytes sets message data from a []byte.
func (*InvokeMethodRequest) WithRawDataString ¶
func (imr *InvokeMethodRequest) WithRawDataString(data string) *InvokeMethodRequest
WithRawDataString sets message data from a string.
func (*InvokeMethodRequest) WithReplay ¶
func (imr *InvokeMethodRequest) WithReplay(enabled bool) *InvokeMethodRequest
WithReplay enables replaying for the data stream.
type InvokeMethodResponse ¶
type InvokeMethodResponse struct {
// contains filtered or unexported fields
}
InvokeMethodResponse holds InternalInvokeResponse protobuf message and provides the helpers to manage it.
func InternalInvokeResponse ¶
func InternalInvokeResponse(pb *internalv1pb.InternalInvokeResponse) (*InvokeMethodResponse, error)
InternalInvokeResponse returns InvokeMethodResponse for InternalInvokeResponse pb to use the helpers.
func NewInvokeMethodResponse ¶
func NewInvokeMethodResponse(statusCode int32, statusMessage string, statusDetails []*anypb.Any) *InvokeMethodResponse
NewInvokeMethodResponse returns new InvokeMethodResponse object with status.
func (*InvokeMethodResponse) CanReplay ¶
func (imr *InvokeMethodResponse) CanReplay() bool
CanReplay returns true if the data stream can be replayed.
func (*InvokeMethodResponse) Close ¶
func (rr *InvokeMethodResponse) Close() (err error)
Close the data stream and replay buffers. It's safe to call Close multiple times on the same object.
func (*InvokeMethodResponse) ContentType ¶
func (imr *InvokeMethodResponse) ContentType() string
ContentType returns the content type of the message.
func (*InvokeMethodResponse) HasMessageData ¶
func (imr *InvokeMethodResponse) HasMessageData() bool
HasMessageData returns true if the message object contains a slice of data buffered.
func (*InvokeMethodResponse) Headers ¶
func (imr *InvokeMethodResponse) Headers() DaprInternalMetadata
Headers gets Headers metadata.
func (*InvokeMethodResponse) IsHTTPResponse ¶
func (imr *InvokeMethodResponse) IsHTTPResponse() bool
IsHTTPResponse returns true if response status code is http response status.
func (*InvokeMethodResponse) Message ¶
func (imr *InvokeMethodResponse) Message() *commonv1pb.InvokeResponse
Message returns message field in InvokeMethodResponse.
func (*InvokeMethodResponse) Proto ¶
func (imr *InvokeMethodResponse) Proto() *internalv1pb.InternalInvokeResponse
Proto returns the internal InvokeMethodResponse Proto object.
func (*InvokeMethodResponse) ProtoWithData ¶
func (imr *InvokeMethodResponse) ProtoWithData() (*internalv1pb.InternalInvokeResponse, error)
ProtoWithData returns a copy of the internal InternalInvokeResponse Proto object with the entire data stream read into the Data property.
func (*InvokeMethodResponse) RawData ¶
func (imr *InvokeMethodResponse) RawData() (r io.Reader)
RawData returns the stream body.
func (*InvokeMethodResponse) RawDataFull ¶
func (imr *InvokeMethodResponse) RawDataFull() ([]byte, error)
RawDataFull returns the entire data read from the stream body.
func (*InvokeMethodResponse) ResetMessageData ¶
func (imr *InvokeMethodResponse) ResetMessageData()
ResetMessageData resets the data inside the message object if present.
func (*InvokeMethodResponse) SetReplay ¶
func (rr *InvokeMethodResponse) SetReplay(enabled bool)
SetReplay enables replaying for the data stream.
func (*InvokeMethodResponse) Status ¶
func (imr *InvokeMethodResponse) Status() *internalv1pb.Status
Status gets Response status.
func (*InvokeMethodResponse) Trailers ¶
func (imr *InvokeMethodResponse) Trailers() DaprInternalMetadata
Trailers gets Trailers metadata.
func (*InvokeMethodResponse) WithContentType ¶
func (imr *InvokeMethodResponse) WithContentType(contentType string) *InvokeMethodResponse
WithContentType sets the content type.
func (*InvokeMethodResponse) WithDataTypeURL ¶
func (imr *InvokeMethodResponse) WithDataTypeURL(val string) *InvokeMethodResponse
WithDataTypeURL sets the type_url property for the data. When a type_url is set, the Content-Type automatically becomes the protobuf one.
func (*InvokeMethodResponse) WithFastHTTPHeaders ¶
func (imr *InvokeMethodResponse) WithFastHTTPHeaders(header *fasthttp.ResponseHeader) *InvokeMethodResponse
WithFastHTTPHeaders populates fasthttp response header to gRPC header metadata.
func (*InvokeMethodResponse) WithHTTPHeaders ¶
func (imr *InvokeMethodResponse) WithHTTPHeaders(headers map[string][]string) *InvokeMethodResponse
WithFastHTTPHeaders populates HTTP response header to gRPC header metadata.
func (*InvokeMethodResponse) WithHeaders ¶
func (imr *InvokeMethodResponse) WithHeaders(headers metadata.MD) *InvokeMethodResponse
WithHeaders sets gRPC response header metadata.
func (*InvokeMethodResponse) WithMessage ¶
func (imr *InvokeMethodResponse) WithMessage(pb *commonv1pb.InvokeResponse) *InvokeMethodResponse
WithMessage sets InvokeResponse pb object to Message field.
func (*InvokeMethodResponse) WithRawData ¶
func (imr *InvokeMethodResponse) WithRawData(data io.Reader) *InvokeMethodResponse
WithRawData sets message data from a readable stream.
func (*InvokeMethodResponse) WithRawDataBytes ¶
func (imr *InvokeMethodResponse) WithRawDataBytes(data []byte) *InvokeMethodResponse
WithRawDataBytes sets message data from a []byte.
func (*InvokeMethodResponse) WithRawDataString ¶
func (imr *InvokeMethodResponse) WithRawDataString(data string) *InvokeMethodResponse
WithRawDataString sets message data from a string.
func (*InvokeMethodResponse) WithReplay ¶
func (imr *InvokeMethodResponse) WithReplay(enabled bool) *InvokeMethodResponse
WithReplay enables replaying for the data stream.
func (*InvokeMethodResponse) WithTrailers ¶
func (imr *InvokeMethodResponse) WithTrailers(trailer metadata.MD) *InvokeMethodResponse
WithTrailers sets Trailer in internal InvokeMethodResponse.