Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v1.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFileName = "config.toml"

Variables

View Source
var ConfigDefaults = map[string]any{
	"admin_username":             "admin",
	"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,
	allow func(net.Addr) bool,
	notify ftpx.OnCloseFunc,
) netx.Handler

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 RateLimitAllowFunc added in v1.26.0

func RateLimitAllowFunc(
	cfg *RateLimitConfig,
	proto RateLimitProtoConfig,
	tel telemetry.Telemetry,
	protocol string,
) func(net.Addr) bool

RateLimitAllowFunc returns a per-IP limit check that counts rejections; it allows everything when disabled.

func RateLimitListenerWrapper added in v1.26.0

func RateLimitListenerWrapper(allow func(net.Addr) bool) func(net.Listener) net.Listener

RateLimitListenerWrapper closes accepted connections over the limit.

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,
	allow func(net.Addr) bool,
	notify smtpx.OnCloseFunc,
) netx.Handler

func SMTPTelemetry

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

Types

type AuditConfig

type AuditConfig struct {
	Enabled bool
}

type Config

type Config struct {
	Domain        string
	AdminUsername string `koanf:"admin_username"`
	IP            string
	GeoIP         GeoIPConfig
	DB            DBConfig
	Audit         AuditConfig
	DNS           DNSConfig
	TLS           TLSConfig
	Telemetry     TelemetryConfig
	RateLimit     RateLimitConfig
	Modules       ModulesConfig
}

func LoadConfig

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

func (Config) Validate

func (c Config) Validate() valid.Problems

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() valid.Problems

type DNSConfig

type DNSConfig struct {
	Zone string
}

type Event added in v1.26.0

type Event struct {
	Event *database.Event
	Match []byte
	// contains filtered or unexported fields
}

type EventsHandler

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

func NewEventsHandler

func NewEventsHandler(
	db *database.DB,
	gdb *geoipx.DB,
	log *slog.Logger,
	workers int,
	capacity int,
) *EventsHandler

func (*EventsHandler) AddNotifier

func (h *EventsHandler) AddNotifier(name string, n *Notifier)

func (*EventsHandler) Emit

func (h *EventsHandler) Emit(ctx context.Context, e *database.Event, match []byte)

type GeoIPConfig

type GeoIPConfig struct {
	Enabled bool
	City    string
	ASN     string
}

func (GeoIPConfig) Validate

func (c GeoIPConfig) Validate() valid.Problems

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() valid.Problems

type Notifier added in v1.26.0

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

Notifier batches notifications per payload and sends them to a notifier from a pool of workers within the notifier's rate limit.

func NewNotifier added in v1.26.0

func NewNotifier(
	notifier modules.Notifier,
	log *slog.Logger,
	tel telemetry.Telemetry,
	workers int,
	opts ...batcher.Option,
) *Notifier

func (*Notifier) Add added in v1.26.0

func (n *Notifier) Add(ctx context.Context, notification *modules.Notification) bool

Add queues notification; ctx is the ctx of the event that triggered it.

func (*Notifier) Close added in v1.26.0

func (n *Notifier) Close()

Close flushes pending batches; the pool stops once they are sent.

type NotifyFunc

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

type RateLimitConfig added in v1.26.0

type RateLimitConfig struct {
	Enabled bool
	Allow   []string
	HTTP    RateLimitProtoConfig
	SMTP    RateLimitProtoConfig
	FTP     RateLimitProtoConfig
}

func (RateLimitConfig) Validate added in v1.26.0

func (c RateLimitConfig) Validate() valid.Problems

type RateLimitProtoConfig added in v1.26.0

type RateLimitProtoConfig struct {
	Rate  float64
	Burst int
}

RateLimitProtoConfig is a per-IP limit in requests per second; zero rate disables it.

func (RateLimitProtoConfig) Validate added in v1.26.0

func (c RateLimitProtoConfig) Validate() valid.Problems

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() valid.Problems

type TLSCustomConfig

type TLSCustomConfig struct {
	Key  string
	Cert string
}

func (TLSCustomConfig) Validate

func (c TLSCustomConfig) Validate() valid.Problems

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() valid.Problems

type TelemetryConfig

type TelemetryConfig struct {
	Enabled bool
}

Jump to

Keyboard shortcuts

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