v1

package
v1.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 27 Imported by: 3

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// DefaultAPIVersion is the default Dapr API version.
	DefaultAPIVersion = internalv1pb.APIVersion_V1 //nolint:nosnakecase
)

Variables

View Source
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

func CodeFromHTTPStatus(httpStatusCode int) codes.Code

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 added in v0.8.0

func ErrorFromHTTPResponseCode(code int, detail string) error

ErrorFromHTTPResponseCode converts http response code to gRPC status error.

func ErrorFromInternalStatus added in v0.8.0

func ErrorFromInternalStatus(internalStatus *internalv1pb.Status) error

ErrorFromInternalStatus converts internal status to gRPC status error.

func HTTPStatusFromCode

func HTTPStatusFromCode(code codes.Code) int

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

func IsJSONContentType(contentType string) bool

IsJSONContentType returns true if contentType is the mime media type for JSON.

func ProtobufToJSON added in v1.0.0

func ProtobufToJSON(message protoreflect.ProtoMessage) ([]byte, error)

ProtobufToJSON serializes Protobuf message to json format.

func ReservedGRPCMetadataToDaprPrefixHeader added in v1.9.0

func ReservedGRPCMetadataToDaprPrefixHeader(key string) string

func WithCustomGRPCMetadata added in v1.5.0

func WithCustomGRPCMetadata(ctx context.Context, md map[string]string) context.Context

WithCustomGRPCMetadata applies a metadata map to the outgoing context metadata.

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 added in v1.12.0

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 added in v1.13.0

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 added in v1.12.0

func (imr *InvokeMethodRequest) AddMetadata(md map[string][]string)

AddMetadata adds new metadata options to the existing set.

func (*InvokeMethodRequest) CanReplay added in v1.10.0

func (imr *InvokeMethodRequest) CanReplay() bool

CanReplay returns true if the data stream can be replayed.

func (*InvokeMethodRequest) Close added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodRequest) ContentType() string

ContenType 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 added in v1.10.6

func (imr *InvokeMethodRequest) GetDataObject() any

GetDataObject returns the data object stored in the object

func (*InvokeMethodRequest) HasMessageData added in v1.10.0

func (imr *InvokeMethodRequest) HasMessageData() bool

HasMessageData returns true if the message object contains a slice of data buffered.

func (*InvokeMethodRequest) Message

Message gets InvokeRequest Message object.

func (*InvokeMethodRequest) Metadata

func (imr *InvokeMethodRequest) Metadata() DaprInternalMetadata

Metadata gets Metadata of InvokeMethodRequest.

func (*InvokeMethodRequest) Proto

Proto returns InternalInvokeRequest Proto object.

func (*InvokeMethodRequest) ProtoWithData added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodRequest) RawDataFull() ([]byte, error)

RawDataFull returns the entire data read from the stream body.

func (*InvokeMethodRequest) ResetMessageData added in v1.10.0

func (imr *InvokeMethodRequest) ResetMessageData()

ResetMessageData resets the data inside the message object if present.

func (*InvokeMethodRequest) SetReplay added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodRequest) WithContentType(contentType string) *InvokeMethodRequest

WithContentType sets the content type.

func (*InvokeMethodRequest) WithCustomHTTPMetadata added in v1.5.0

func (imr *InvokeMethodRequest) WithCustomHTTPMetadata(md map[string]string) *InvokeMethodRequest

WithCustomHTTPMetadata applies a metadata map to a InvokeMethodRequest.

func (*InvokeMethodRequest) WithDataObject added in v1.10.6

func (imr *InvokeMethodRequest) WithDataObject(data any) *InvokeMethodRequest

WithDataObject sets message from an object which will be serialized as JSON

func (*InvokeMethodRequest) WithDataTypeURL added in v1.11.5

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 added in v0.9.0

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 added in v1.12.0

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 added in v1.10.0

func (imr *InvokeMethodRequest) WithRawDataBytes(data []byte) *InvokeMethodRequest

WithRawDataBytes sets message data from a []byte.

func (*InvokeMethodRequest) WithRawDataString added in v1.10.0

func (imr *InvokeMethodRequest) WithRawDataString(data string) *InvokeMethodRequest

WithRawDataString sets message data from a string.

func (*InvokeMethodRequest) WithReplay added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodResponse) CanReplay() bool

CanReplay returns true if the data stream can be replayed.

func (*InvokeMethodResponse) Close added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodResponse) ContentType() string

ContenType returns the content type of the message.

func (*InvokeMethodResponse) HasMessageData added in v1.10.0

func (imr *InvokeMethodResponse) HasMessageData() bool

HasMessageData returns true if the message object contains a slice of data buffered.

func (*InvokeMethodResponse) Headers

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

Message returns message field in InvokeMethodResponse.

func (*InvokeMethodResponse) Proto

Proto returns the internal InvokeMethodResponse Proto object.

func (*InvokeMethodResponse) ProtoWithData added in v1.10.0

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 added in v1.10.0

func (imr *InvokeMethodResponse) RawDataFull() ([]byte, error)

RawDataFull returns the entire data read from the stream body.

func (*InvokeMethodResponse) ResetMessageData added in v1.10.0

func (imr *InvokeMethodResponse) ResetMessageData()

ResetMessageData resets the data inside the message object if present.

func (*InvokeMethodResponse) SetReplay added in v1.10.0

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

Trailers gets Trailers metadata.

func (*InvokeMethodResponse) WithContentType added in v1.10.0

func (imr *InvokeMethodResponse) WithContentType(contentType string) *InvokeMethodResponse

WithContentType sets the content type.

func (*InvokeMethodResponse) WithDataTypeURL added in v1.11.5

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 added in v1.10.0

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

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 added in v1.10.0

func (imr *InvokeMethodResponse) WithRawDataBytes(data []byte) *InvokeMethodResponse

WithRawDataBytes sets message data from a []byte.

func (*InvokeMethodResponse) WithRawDataString added in v1.10.0

func (imr *InvokeMethodResponse) WithRawDataString(data string) *InvokeMethodResponse

WithRawDataString sets message data from a string.

func (*InvokeMethodResponse) WithReplay added in v1.10.0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL