types

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callbacks

type Callbacks struct {
	// OnConnecting is called when there is a new incoming connection.
	// The handler can examine the request and either accept or reject the connection.
	// To accept:
	//   Return ConnectionResponse with Accept=true. ConnectionCallbacks MUST be set to an
	//   instance of the ConnectionCallbacks struct to handle the connection callbacks.
	//   HTTPStatusCode and HTTPResponseHeader are ignored.
	//
	// To reject:
	//   Return ConnectionResponse with Accept=false. HTTPStatusCode MUST be set to
	//   non-zero value to indicate the rejection reason (typically 401, 429 or 503).
	//   HTTPResponseHeader may be optionally set (e.g. "Retry-After: 30").
	//   ConnectionCallbacks is ignored.
	OnConnecting func(request *http.Request) ConnectionResponse
}

func (*Callbacks) SetDefaults added in v0.18.0

func (c *Callbacks) SetDefaults()

type Connection

type Connection interface {
	// Connection returns the underlying net.Conn
	Connection() net.Conn

	// Send a message. Should not be called concurrently for the same Connection instance.
	// Can be called only for WebSocket connections. Will return an error for plain HTTP
	// connections.
	// Blocks until the message is sent.
	// Should return as soon as possible if the ctx is cancelled.
	Send(ctx context.Context, message *protobufs.ServerToAgent) error

	// Disconnect closes the network connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Disconnect() error
}

Connection represents one OpAMP connection. The implementation MUST be a comparable type so that it can be used as a map key.

type ConnectionCallbacks added in v0.7.0

type ConnectionCallbacks struct {

	// OnConnected is called when an incoming OpAMP connection is successfully
	// established after OnConnecting() returns.
	OnConnected func(ctx context.Context, conn Connection)

	// OnMessage is called when a message is received from the connection. Can happen
	// only after OnConnected().
	// When the returned ServerToAgent message is nil, WebSocket will not send a
	// message to the Agent, and the HTTP request will respond to an empty message.
	// If the return is not nil it will be sent as a response to the Agent.
	// For plain HTTP requests once OnMessage returns and the response is sent
	// to the Agent the OnConnectionClose message will be called immediately.
	OnMessage func(ctx context.Context, conn Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent

	// OnConnectionClose is called when the OpAMP connection is closed.
	OnConnectionClose func(conn Connection)

	// OnReadMessageError is called when an error occurs while reading or deserializing a message.
	OnReadMessageError func(conn Connection, mt int, msgByte []byte, err error)

	// OnMessageResponseError is called when an error occurs while sending the response message from the OnMessage loop.
	OnMessageResponseError func(conn Connection, message *protobufs.ServerToAgent, err error)
}

ConnectionCallbacks specifies callbacks for a specific connection. An instance of this struct MUST be set on the ConnectionResponse returned by the OnConnecting callback if Accept=true. The instance can be shared by all connections or can be unique for each connection.

func (*ConnectionCallbacks) SetDefaults added in v0.18.0

func (c *ConnectionCallbacks) SetDefaults()

type ConnectionResponse

type ConnectionResponse struct {
	Accept              bool
	HTTPStatusCode      int
	HTTPResponseHeader  map[string]string
	ConnectionCallbacks ConnectionCallbacks
}

ConnectionResponse is the return type of the OnConnecting callback.

Jump to

Keyboard shortcuts

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