server

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFileName = "config.toml"

Variables

View Source
var ConfigDefaults = map[string]any{
	"tls.type":                   "letsencrypt",
	"tls.letsencrypt.directory":  "./tls",
	"tls.letsencrypt.ca_dir_url": "https://acme-v02.api.letsencrypt.org/directory",
	"modules.enabled":            "api",
	"modules.api.port":           31337,
}

Functions

func DNSDefaultRecords

func DNSDefaultRecords(origin string, ip net.IP) *dnsx.Records

func DNSHandler

func DNSHandler(
	cfg *DNSConfig,
	db *database.DB,
	tel telemetry.Telemetry,
	origin string,
	ip net.IP,
	notify dnsx.NofitifyFunc,
) dnsx.HandlerProvider

func DNSTelemetryHandler

func DNSTelemetryHandler(tel telemetry.Telemetry, next dnsx.Handler) dnsx.Handler

func DNSZoneFileRecords

func DNSZoneFileRecords(filePath, origin string, ip net.IP) *dnsx.Records

func FTPHandler

func FTPHandler(
	domain string,
	log *slog.Logger,
	tel telemetry.Telemetry,
	notify ftpx.OnCloseFunc,
) netx.Handler

func FTPListenerWrapper

func FTPListenerWrapper(maxBytes int64, idleTimeout time.Duration) func(net.Listener) net.Listener

func FTPTelemetry

func FTPTelemetry(next netx.Handler, tel telemetry.Telemetry) netx.Handler

func HTTPDefault

func HTTPDefault(w http.ResponseWriter, r *http.Request)

func HTTPHandler

func HTTPHandler(
	db *database.DB,
	tel telemetry.Telemetry,
	origin string,
	notify httpx.NotifyFunc,
) http.Handler

func HTTPTelemetry

func HTTPTelemetry(next http.Handler, tel telemetry.Telemetry) http.Handler

func Run

func Run(
	ctx context.Context,
	stdout io.Writer,
	stderr io.Writer,
	dir fs.FS,
	environFunc func() []string,
) error

func SMTPHandler

func SMTPHandler(
	domain string,
	log *slog.Logger,
	tel telemetry.Telemetry,
	tlsConfig *tls.Config,
	notify smtpx.OnCloseFunc,
) netx.Handler

func SMTPListenerWrapper

func SMTPListenerWrapper(maxBytes int64, idleTimeout time.Duration) func(net.Listener) net.Listener

func SMTPTelemetry

func SMTPTelemetry(next netx.Handler, tel telemetry.Telemetry) netx.Handler

Types

type AuditConfig

type AuditConfig struct {
	Enabled bool
}

func (AuditConfig) Validate

func (c AuditConfig) Validate() error

type Config

type Config struct {
	Domain    string
	IP        string
	GeoIP     GeoIPConfig
	DB        DBConfig
	Audit     AuditConfig
	DNS       DNSConfig
	TLS       TLSConfig
	Telemetry TelemetryConfig
	Modules   ModulesConfig
}

func LoadConfig

func LoadConfig(
	dir fs.FS,
	environFunc func() []string,
) (*Config, error)

func (Config) Validate

func (c Config) Validate() error

type Controller

type Controller interface {
	Start() error
}

func Modules

func Modules(
	cfg *ModulesConfig,
	log *slog.Logger,
	tel telemetry.Telemetry,
	tls *tls.Config,
	svc service.ServerService,
	domain string,
) ([]Controller, []modules.Notifier, error)

type DBConfig

type DBConfig struct {
	DSN string
}

func (DBConfig) Validate

func (c DBConfig) Validate() error

type DNSConfig

type DNSConfig struct {
	Zone string
}

func (DNSConfig) Validate

func (c DNSConfig) Validate() error

type EventsHandler

type EventsHandler struct {
	// contains filtered or unexported fields
}

func NewEventsHandler

func NewEventsHandler(
	db *database.DB,
	gdb *geoipx.DB,
	log *slog.Logger,
	tel telemetry.Telemetry,
	cache cache.Cache,
	workers int,
	capacity int,
) *EventsHandler

func (*EventsHandler) AddNotifier

func (h *EventsHandler) AddNotifier(name string, notifier modules.Notifier)

func (*EventsHandler) Emit

func (h *EventsHandler) Emit(ctx context.Context, e *database.Event)

func (*EventsHandler) Start

func (h *EventsHandler) Start() error

type GeoIPConfig

type GeoIPConfig struct {
	Enabled bool
	City    string
	ASN     string
}

func (GeoIPConfig) Validate

func (c GeoIPConfig) Validate() error

type ModulesConfig

type ModulesConfig struct {
	Enabled []string

	// TODO: dynamic modules config (something like json.RawMessage) to be able to not include
	// unnecessary modules in binary.
	Telegram telegram.Config
	API      api.Config
	Lark     lark.Config
	Slack    slack.Config
}

func (ModulesConfig) Validate

func (c ModulesConfig) Validate() error

type NotifyFunc

type NotifyFunc func(net.Addr, []byte, map[string]any)

type TLS

type TLS struct {
	// contains filtered or unexported fields
}

func NewTLS

func NewTLS(cfg *TLSConfig, log *slog.Logger, domain string, provider challenge.Provider) (*TLS, error)

func (*TLS) GetConfig

func (t *TLS) GetConfig() (*tls.Config, error)

func (*TLS) Start

func (t *TLS) Start() error

func (*TLS) Wait

func (t *TLS) Wait()

type TLSConfig

type TLSConfig struct {
	Type        string
	Custom      TLSCustomConfig
	LetsEncrypt TLSLetsEncryptConfig
}

func (TLSConfig) Validate

func (c TLSConfig) Validate() error

type TLSCustomConfig

type TLSCustomConfig struct {
	Key  string
	Cert string
}

func (TLSCustomConfig) Validate

func (c TLSCustomConfig) Validate() error

type TLSLetsEncryptConfig

type TLSLetsEncryptConfig struct {
	Email      string
	Directory  string
	CADirURL   string `koanf:"ca_dir_url"`
	CAInsecure bool   `koanf:"ca_insecure"`
}

func (TLSLetsEncryptConfig) Validate

func (c TLSLetsEncryptConfig) Validate() error

type TelemetryConfig

type TelemetryConfig struct {
	Enabled bool
}

func (TelemetryConfig) Validate

func (c TelemetryConfig) Validate() error

Jump to

Keyboard shortcuts

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