listeners

package
v0.0.0-...-098fa9b Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func (l *Listener) GetDrainTimeout() time.Duration

GetDrainTimeout extracts the drain timeout with a fallback to default value

func (*Listener) GetHTTPOptions

func (l *Listener) GetHTTPOptions() (options.HTTP, bool)

GetHTTPOptions extracts HTTPOptions from a Listener

func (*Listener) GetIdleTimeout

func (l *Listener) GetIdleTimeout() time.Duration

GetIdleTimeout extracts the idle timeout with a fallback to default value

func (*Listener) GetOptionsType

func (l *Listener) GetOptionsType() options.Type

GetOptionsType returns the type of the listener options

func (*Listener) GetReadTimeout

func (l *Listener) GetReadTimeout() time.Duration

GetReadTimeout extracts the read timeout with a fallback to default value

func (*Listener) GetTypeString

func (l *Listener) GetTypeString() string

GetTypeString returns a string representation of the listener type

func (*Listener) GetWriteTimeout

func (l *Listener) GetWriteTimeout() time.Duration

GetWriteTimeout extracts the write timeout with a fallback to default value

func (*Listener) String

func (l *Listener) String() string

String returns a concise representation of a Listener

func (*Listener) ToTree

func (l *Listener) ToTree() *fancy.ComponentTree

ToTree returns a tree visualization of this Listener

func (*Listener) Validate

func (l *Listener) Validate() error

Validate performs validation for a 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

type Type

type Type int32

Type represents the listener type

const (
	TypeUnspecified Type = 0
	TypeHTTP        Type = 1
)

Listener types

func (Type) String

func (t Type) String() string

String returns a string representation of the Type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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