Documentation
¶
Overview ¶
Package listeners provides configuration types and utilities for network listeners in the firelynx server.
This package defines the domain model for listener configurations, supporting multiple protocol types through the options sub-package. It handles validation, conversion between domain and protocol buffer representations, and provides helper methods for accessing protocol-specific configurations.
The main types include: - Listener: Represents a single listener with an ID, address, and protocol-specific options - ListenerCollection: A slice of Listener objects with validation and conversion methods
Relationship with Endpoints: Endpoints are associated with listeners through their ListenerID field. Use the endpoints collection methods or config wrapper methods to query this relationship.
Thread Safety: The listener configuration objects are not thread-safe and should be protected when accessed concurrently. These objects are typically loaded during startup or configuration reload operations, which should be synchronized.
Usage Example:
// Create an HTTP listener
httpListener := listeners.Listener{
ID: "http-main",
Address: "0.0.0.0:8080",
Type: TypeHTTP,
Options: options.HTTP{
ReadTimeout: time.Second * 30,
WriteTimeout: time.Second * 30,
},
}
// Create a collection
listenerCollection := listeners.ListenerCollection{httpListener}
// Validate the configuration
if err := listenerCollection.Validate(); err != nil {
return err
}
Package listeners provides domain model for network listeners
Index ¶
- Variables
- type Listener
- func (l *Listener) GetDrainTimeout() time.Duration
- func (l *Listener) GetHTTPOptions() (options.HTTP, bool)
- func (l *Listener) GetIdleTimeout() time.Duration
- func (l *Listener) GetOptionsType() options.Type
- func (l *Listener) GetReadTimeout() time.Duration
- func (l *Listener) GetTypeString() string
- func (l *Listener) GetWriteTimeout() time.Duration
- func (l *Listener) String() string
- func (l *Listener) ToTree() *fancy.ComponentTree
- func (l *Listener) Validate() error
- type ListenerCollection
- func (lc ListenerCollection) All() iter.Seq[Listener]
- func (lc ListenerCollection) FindByID(id string) (Listener, bool)
- func (lc ListenerCollection) FindByType(listenerType Type) iter.Seq[Listener]
- func (lc ListenerCollection) GetHTTPListeners() iter.Seq[Listener]
- func (listeners ListenerCollection) ToProto() []*pb.Listener
- type Type
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidListenerType = errors.New("invalid listener type")
)
Common listener-specific error types
Functions ¶
This section is empty.
Types ¶
type Listener ¶
type Listener struct {
ID string `env_interpolation:"no"`
Address string `env_interpolation:"yes"`
Type Type
Options options.Options
}
Listener represents a network listener configuration
func (*Listener) GetDrainTimeout ¶
GetDrainTimeout extracts the drain timeout with a fallback to default value
func (*Listener) GetHTTPOptions ¶
GetHTTPOptions extracts HTTPOptions from a Listener
func (*Listener) GetIdleTimeout ¶
GetIdleTimeout extracts the idle timeout with a fallback to default value
func (*Listener) GetOptionsType ¶
GetOptionsType returns the type of the listener options
func (*Listener) GetReadTimeout ¶
GetReadTimeout extracts the read timeout with a fallback to default value
func (*Listener) GetTypeString ¶
GetTypeString returns a string representation of the listener type
func (*Listener) GetWriteTimeout ¶
GetWriteTimeout extracts the write timeout with a fallback to default value
func (*Listener) ToTree ¶
func (l *Listener) ToTree() *fancy.ComponentTree
ToTree returns a tree visualization of this Listener
type ListenerCollection ¶
type ListenerCollection []Listener
ListenerCollection is a collection of Listener objects
func FromProto ¶
func FromProto(pbListeners []*pb.Listener) (ListenerCollection, error)
FromProto converts protobuf Listener messages to a domain Listeners collection
func NewListenerCollection ¶
func NewListenerCollection(listeners ...Listener) ListenerCollection
NewListenerCollection creates a new ListenerCollection with the given listeners.
func (ListenerCollection) All ¶
func (lc ListenerCollection) All() iter.Seq[Listener]
All returns an iterator over all listeners in the collection. This enables clean iteration: for listener := range collection.All() { ... }
func (ListenerCollection) FindByID ¶
func (lc ListenerCollection) FindByID(id string) (Listener, bool)
FindByID finds a listener by ID, returning (Listener, bool)
func (ListenerCollection) FindByType ¶
func (lc ListenerCollection) FindByType(listenerType Type) iter.Seq[Listener]
FindByType returns an iterator over listeners of a specific type. This enables clean iteration: for listener := range collection.FindByType(TypeHTTP) { ... }
func (ListenerCollection) GetHTTPListeners ¶
func (lc ListenerCollection) GetHTTPListeners() iter.Seq[Listener]
GetHTTPListeners returns an iterator over listeners of HTTP type
func (ListenerCollection) ToProto ¶
func (listeners ListenerCollection) ToProto() []*pb.Listener
ToProto converts a Listeners collection to a slice of protobuf Listener messages