extensions

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 1 Imported by: 36

Documentation

Index

Constants

View Source
const Prefix = "asyncapi-"

Prefix is the prefix used for all context keys in order to avoid collision with other keys that can be present in context.

Variables

This section is empty.

Functions

func IfContextSetWith

func IfContextSetWith[T any](ctx context.Context, key ContextKey, fn func(value T))

IfContextSetWith executes the function if the key is set in the context as a string.

func IfContextValueEquals

func IfContextValueEquals[T comparable](ctx context.Context, key ContextKey, expected T, fn func())

IfContextValueEquals executes the function if the key is set in the context as a given type and the value is equal to the expected value.

Types

type BrokerController

type BrokerController interface {
	// Publish a message to the broker
	Publish(ctx context.Context, channel string, mw BrokerMessage) error

	// Subscribe to messages from the broker
	Subscribe(ctx context.Context, channel string) (msgs chan BrokerMessage, stop chan interface{}, err error)
}

BrokerController represents the functions that should be implemented to connect the broker to the application or the user.

type BrokerMessage

type BrokerMessage struct {
	Headers map[string][]byte
	Payload []byte
}

BrokerMessage is a wrapper that will contain all information regarding a message.

type ContextKey

type ContextKey string

ContextKey is the type of the keys used in the context.

const (
	// ContextKeyIsProvider is the name of the provider this data is coming from.
	// When coming from a generated user, it is `asyncapi`.
	ContextKeyIsProvider ContextKey = Prefix + "provider"
	// ContextKeyIsChannel is the name of the channel this data is coming from.
	ContextKeyIsChannel ContextKey = Prefix + "channel"
	// ContextKeyIsMessageDirection is the direction this data is coming from.
	// It can be either "publication" or "reception".
	ContextKeyIsMessageDirection ContextKey = Prefix + "operation"
	// ContextKeyIsBrokerMessage is the message that has been sent or received from/to the broker.
	ContextKeyIsBrokerMessage ContextKey = Prefix + "broker-message"
	// ContextKeyIsMessage is the message that has been sent or received.
	ContextKeyIsMessage ContextKey = Prefix + "message"
	// ContextKeyIsCorrelationID is the correlation ID of the message.
	ContextKeyIsCorrelationID ContextKey = Prefix + "correlationID"
)

func (ContextKey) String

func (k ContextKey) String() string

String returns the string representation of the key.

type DummyLogger

type DummyLogger struct {
}

DummyLogger is a logger that does not log anything.

func (DummyLogger) Error

func (dl DummyLogger) Error(_ context.Context, _ string, _ ...LogInfo)

Error logs error based on a message and key-value elements.

func (DummyLogger) Info

func (dl DummyLogger) Info(_ context.Context, _ string, _ ...LogInfo)

Info logs information based on a message and key-value elements.

func (DummyLogger) Warning added in v0.19.4

func (dl DummyLogger) Warning(_ context.Context, _ string, _ ...LogInfo)

Warning logs information based on a message and key-value elements.

type LogInfo

type LogInfo struct {
	Key   string
	Value interface{}
}

LogInfo is a key-value pair that will be added to the log.

type Logger

type Logger interface {
	// Info logs information based on a message and key-value elements
	Info(ctx context.Context, msg string, info ...LogInfo)

	// Warning logs information based on a message and key-value elements
	// This levels indicates a non-expected state but that does not prevent the
	// application to work properly
	Warning(ctx context.Context, msg string, info ...LogInfo)

	// Error logs error based on a message and key-value elements
	Error(ctx context.Context, msg string, info ...LogInfo)
}

Logger is the interface that must be implemented by a logger.

type Middleware

type Middleware func(ctx context.Context, next NextMiddleware) context.Context

Middleware is the signature of the function that needs to be implemented to use middleware functionnality

You can call the next middleware during the execution of the defined middleware in order to wrap code execution (for example, to time execution, or recover in case of panic).

type NextMiddleware

type NextMiddleware func(ctx context.Context)

NextMiddleware represents the next middleware that can be executed during the previous middleware. If this is already the last middleware, it will execute the appropriate autogenerated code for reception/sending of messages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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