Documentation ¶
Overview ¶
Package client holds the recommended entry points for interacting with the CloudEvents Golang SDK. The client wraps a selected transport. The client adds validation and defaulting for sending events, and flexible receiver method registration. For full details, read the `client.Client` documentation.
Index ¶
- Variables
- func DefaultIDToUUIDIfNotSet(ctx context.Context, event event.Event) event.Event
- func DefaultTimeToNowIfNotSet(ctx context.Context, event event.Event) event.Event
- func EventTraceAttributes(e event.EventReader) []trace.Attribute
- func TraceSpan(ctx context.Context, e event.Event) (context.Context, *trace.Span)
- type Client
- type EventDefaulter
- type EventReceiver
- type Invoker
- type Option
- type ReceiveFull
Constants ¶
This section is empty.
Variables ¶
var ( // LatencyMs measures the latency in milliseconds for the CloudEvents // client methods. LatencyMs = stats.Float64("cloudevents.io/sdk-go/client/latency", "The latency in milliseconds for the CloudEvents client methods.", "ms") )
var ( // LatencyView is an OpenCensus view that shows client method latency. LatencyView = &view.View{ Name: "client/latency", Measure: LatencyMs, Description: "The distribution of latency inside of client for CloudEvents.", Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), TagKeys: observability.LatencyTags(), } )
Functions ¶
func DefaultIDToUUIDIfNotSet ¶
DefaultIDToUUIDIfNotSet will inspect the provided event and assign a UUID to context.ID if it is found to be empty.
func DefaultTimeToNowIfNotSet ¶
DefaultTimeToNowIfNotSet will inspect the provided event and assign a new Timestamp to context.Time if it is found to be nil or zero.
func EventTraceAttributes ¶
func EventTraceAttributes(e event.EventReader) []trace.Attribute
Types ¶
type Client ¶
type Client interface { // Send will transmit the given event over the client's configured transport. Send(ctx context.Context, event event.Event) error // Request will transmit the given event over the client's configured // transport and return any response event. Request(ctx context.Context, event event.Event) (*event.Event, error) // StartReceiver will register the provided function for callback on receipt // of a cloudevent. It will also start the underlying protocol as it has // been configured. // This call is blocking. // Valid fn signatures are: // * func() // * func() error // * func(context.Context) // * func(context.Context) protocol.Result // * func(event.Event) // * func(event.Event) protocol.Result // * func(context.Context, event.Event) // * func(context.Context, event.Event) protocol.Result // * func(event.Event) *event.Event // * func(event.Event) (*event.Event, protocol.Result) // * func(context.Context, event.Event) *event.Event // * func(context.Context, event.Event) (*event.Event, protocol.Result) StartReceiver(ctx context.Context, fn interface{}) error }
Client interface defines the runtime contract the CloudEvents client supports.
func NewDefault ¶
NewDefault provides the good defaults for the common case using an HTTP Protocol client. The http transport has had WithBinaryEncoding http transport option applied to it. The client will always send Binary encoding but will inspect the outbound event context and match the version. The WithTimeNow, and WithUUIDs client options are also applied to the client, all outbound events will have a time and id set if not already present.
func NewObserved ¶
New produces a new client with the provided transport object and applied client options.
type EventDefaulter ¶
EventDefaulter is the function signature for extensions that are able to perform event defaulting.
func NewDefaultDataContentTypeIfNotSet ¶
func NewDefaultDataContentTypeIfNotSet(contentType string) EventDefaulter
NewDefaultDataContentTypeIfNotSet returns a defaulter that will inspect the provided event and set the provided content type if content type is found to be empty.
type EventReceiver ¶
type EventReceiver struct {
// contains filtered or unexported fields
}
func NewHTTPReceiveHandler ¶
func (*EventReceiver) ServeHTTP ¶
func (r *EventReceiver) ServeHTTP(rw http.ResponseWriter, req *http.Request)
type Option ¶
type Option func(interface{}) error
Option is the function signature required to be considered an client.Option.
func WithEventDefaulter ¶
func WithEventDefaulter(fn EventDefaulter) Option
WithEventDefaulter adds an event defaulter to the end of the defaulter chain.
func WithForceBinary ¶
func WithForceBinary() Option
func WithForceStructured ¶
func WithForceStructured() Option
func WithTimeNow ¶
func WithTimeNow() Option
WithTimeNow adds DefaultTimeToNowIfNotSet event defaulter to the end of the defaulter chain.
func WithTracePropagation ¶
func WithTracePropagation() Option
WithTracePropagation enables trace propagation via the distributed tracing extension.