Documentation
¶
Overview ¶
Package endpoint defines the interface for communication endpoints in the GoBroke system. Endpoints handle the actual message transmission between clients and the broker.
Package endpoint provides interfaces and implementations for communication endpoints.
Index ¶
- type Endpoint
- type StubEndpoint
- func (s *StubEndpoint) Disconnect(client *clients.Client) error
- func (s *StubEndpoint) Receiver(ch chan types.Message) error
- func (s *StubEndpoint) Sender(ch chan types.Message) error
- func (s *StubEndpoint) SimulateClientConnection() *clients.Client
- func (s *StubEndpoint) SimulateClientMessage(from *clients.Client, to []*clients.Client, message []byte)
- func (s *StubEndpoint) Start(ctx context.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint interface {
// Sender sets up the channel for outgoing messages from the broker to clients.
// Returns an error if the sender channel cannot be established.
Sender(chan types.Message) error
// Receiver sets up the channel for incoming messages from clients to the broker.
// Returns an error if the receiver channel cannot be established.
Receiver(chan types.Message) error
// Disconnect terminates a client's connection to the endpoint.
// Returns an error if the client cannot be disconnected properly.
Disconnect(client *clients.Client) error
// Start begins the endpoint's message processing operations.
// It runs until the provided context is cancelled.
Start(ctx context.Context)
}
Endpoint defines the interface that all communication endpoints must implement. An endpoint is responsible for managing client connections and message transmission.
type StubEndpoint ¶ added in v0.0.2
type StubEndpoint struct {
// contains filtered or unexported fields
}
StubEndpoint provides a basic in-memory implementation of the Endpoint interface. It's useful for testing and as a reference implementation.
func NewStubEndpoint ¶ added in v0.0.2
func NewStubEndpoint() *StubEndpoint
NewStubEndpoint creates a new instance of StubEndpoint. It initializes the necessary channels and client storage.
func (*StubEndpoint) Disconnect ¶ added in v0.0.2
func (s *StubEndpoint) Disconnect(client *clients.Client) error
Disconnect implements the Endpoint interface by removing the client from the endpoint's client map.
func (*StubEndpoint) Receiver ¶ added in v0.0.2
func (s *StubEndpoint) Receiver(ch chan types.Message) error
Receiver implements the Endpoint interface by setting up the channel for receiving messages from clients.
func (*StubEndpoint) Sender ¶ added in v0.0.2
func (s *StubEndpoint) Sender(ch chan types.Message) error
Sender implements the Endpoint interface by setting up the channel for sending messages to clients.
func (*StubEndpoint) SimulateClientConnection ¶ added in v0.0.2
func (s *StubEndpoint) SimulateClientConnection() *clients.Client
SimulateClientConnection creates a new client and simulates its connection to the endpoint. This is useful for testing.
func (*StubEndpoint) SimulateClientMessage ¶ added in v0.0.2
func (s *StubEndpoint) SimulateClientMessage(from *clients.Client, to []*clients.Client, message []byte)
SimulateClientMessage simulates a client sending a message through the endpoint. This is useful for testing message flow.
func (*StubEndpoint) Start ¶ added in v0.0.2
func (s *StubEndpoint) Start(ctx context.Context)
Start implements the Endpoint interface. In this stub implementation, it simply waits for context cancellation.