web

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MinPasswordLength = 8

MinPasswordLength is the minimum required password length.

Variables

View Source
var (
	Version   = "dev"
	BuildTime = "unknown"
	GoVersion = "unknown"
)

Version info variables — set at build time from main.go.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password using bcrypt. Returns an error if the password is shorter than MinPasswordLength.

func SPAHandler

func SPAHandler() http.Handler

SPAHandler serves the embedded React SPA, falling back to index.html for client-side routing.

func StartZabbixAgent

func StartZabbixAgent(ctx context.Context, addr string, m *metrics.Metrics, c *cache.Cache, logger *slog.Logger) error

StartZabbixAgent starts a TCP listener implementing the Zabbix agent protocol (ZBXD header).

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword checks if a password meets minimum requirements.

Types

type AdminServer

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

AdminServer provides the admin dashboard HTTP backend.

func NewAdminServer

func NewAdminServer(cfg *config.Config, c *cache.Cache, m *metrics.Metrics, r *resolver.Resolver, logger *slog.Logger, bl *blocklist.Manager) (*AdminServer, error)

NewAdminServer creates a new AdminServer. The bl parameter is optional and may be nil when the blocklist feature is disabled.

func (*AdminServer) CertManager added in v0.5.5

func (s *AdminServer) CertManager() *certmanager.Manager

CertManager returns the auto-TLS certificate manager (may be nil).

func (*AdminServer) RecordQuery

func (s *AdminServer) RecordQuery(client, qname, qtype, rcode string, cached bool, durationMs float64)

RecordQuery is called from the DNS handler hook to log a query.

func (*AdminServer) SetCertManager added in v0.5.5

func (s *AdminServer) SetCertManager(cm *certmanager.Manager)

SetCertManager sets the auto-TLS certificate manager.

func (*AdminServer) SetConfigPath

func (s *AdminServer) SetConfigPath(path string)

func (*AdminServer) SetDoHEnabled

func (s *AdminServer) SetDoHEnabled(enabled bool)

SetDoHEnabled enables or disables the DoH endpoint.

func (*AdminServer) SetDoHHandler

func (s *AdminServer) SetDoHHandler(h server.Handler)

SetDoHHandler sets the DNS handler used for DoH requests.

func (*AdminServer) Start

func (s *AdminServer) Start(ctx context.Context) error

Start starts the HTTP server and blocks until the context is cancelled.

func (*AdminServer) StartUpdateChecker

func (s *AdminServer) StartUpdateChecker(ctx context.Context)

StartUpdateChecker runs a background goroutine that periodically checks for updates.

type Bucket

type Bucket struct {
	Timestamp          string  `json:"timestamp"`
	Queries            int64   `json:"queries"`
	CacheHits          int64   `json:"cache_hits"`
	CacheMisses        int64   `json:"cache_misses"`
	Errors             int64   `json:"errors"`
	AvgLatencyMs       float64 `json:"avg_latency_ms"`
	CacheHitRatio      float64 `json:"cache_hit_ratio"`
	FallbackQueries    int64   `json:"fallback_queries"`
	FallbackRecoveries int64   `json:"fallback_recoveries"`
}

Bucket represents an aggregated time-series data point.

type QueryEntry

type QueryEntry struct {
	ID           uint64  `json:"id"`
	GlobalNum    uint64  `json:"global_num"`
	ClientNum    uint64  `json:"client_num"`
	Timestamp    string  `json:"ts"`
	Client       string  `json:"client"`
	QName        string  `json:"qname"`
	QType        string  `json:"qtype"`
	RCode        string  `json:"rcode"`
	Cached       bool    `json:"cached"`
	DurationMs   float64 `json:"duration_ms"`
	Blocked      bool    `json:"blocked"`
	DNSSECStatus string  `json:"dnssec_status,omitempty"`
}

QueryEntry represents a single DNS query log entry.

type QueryLog

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

QueryLog is a thread-safe ring buffer of DNS query entries with pub/sub support.

func NewQueryLog

func NewQueryLog(capacity int) *QueryLog

NewQueryLog creates a new QueryLog with the given ring buffer capacity.

func (*QueryLog) Recent

func (ql *QueryLog) Recent(n int) []QueryEntry

Recent returns the last n entries in chronological order.

func (*QueryLog) Record

func (ql *QueryLog) Record(entry QueryEntry)

Record adds an entry to the ring buffer and fans out to all subscribers.

func (*QueryLog) Subscribe

func (ql *QueryLog) Subscribe() (uint64, <-chan QueryEntry)

Subscribe returns a unique subscription ID and a channel that receives new entries.

func (*QueryLog) Unsubscribe

func (ql *QueryLog) Unsubscribe(id uint64)

Unsubscribe removes a subscriber and closes its channel.

type SetupRequest

type SetupRequest struct {
	ListenAddr     string  `json:"listen_addr"`
	WebAddr        string  `json:"web_addr"`
	Username       string  `json:"username"`
	Password       string  `json:"password"`
	MaxCacheSize   int     `json:"max_cache_size"`
	MaxDepth       int     `json:"max_depth"`
	RateLimitRate  float64 `json:"rate_limit_rate"`
	RateLimitBurst int     `json:"rate_limit_burst"`
	LogLevel       string  `json:"log_level"`
	LogFormat      string  `json:"log_format"`
}

SetupRequest represents the JSON body for the setup completion endpoint.

type TimeSeriesAggregator

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

TimeSeriesAggregator collects rolling 1-hour bucketed counters at 1-second intervals.

func NewTimeSeriesAggregator

func NewTimeSeriesAggregator() *TimeSeriesAggregator

NewTimeSeriesAggregator creates a new time-series aggregator.

func (*TimeSeriesAggregator) Record

func (ts *TimeSeriesAggregator) Record(cached bool, latencyMs float64, isError bool)

Record records a single query into the current time bucket.

func (*TimeSeriesAggregator) RecordFallback added in v0.6.2

func (ts *TimeSeriesAggregator) RecordFallback(query, recovery int64)

RecordFallback records one fallback query attempt and optionally one recovery.

func (*TimeSeriesAggregator) Snapshot

func (ts *TimeSeriesAggregator) Snapshot(window time.Duration) []Bucket

Snapshot returns all buckets within the given time window.

func (*TimeSeriesAggregator) SnapshotAggregated added in v0.5.2

func (ts *TimeSeriesAggregator) SnapshotAggregated(window, interval time.Duration) []Bucket

SnapshotAggregated returns buckets within the given window, aggregated into super-buckets of the given interval. For example, window=15m and interval=1m produces ~15 data points. Each super-bucket sums queries/hits/misses/errors and computes a weighted-average latency plus cache-hit ratio.

type TopEntry

type TopEntry struct {
	Key   string `json:"key"`
	Count int64  `json:"count"`
}

TopEntry represents a single entry in a top-N leaderboard.

type TopTracker

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

TopTracker is a concurrent top-N tracker that counts occurrences of string keys.

func NewTopTracker

func NewTopTracker(limit int) *TopTracker

NewTopTracker creates a new TopTracker with the given limit.

func (*TopTracker) Inc

func (t *TopTracker) Inc(key string)

Inc increments the count for the given key. If the map exceeds limit*10, low-count entries are pruned.

func (*TopTracker) Top

func (t *TopTracker) Top(n int) []TopEntry

Top returns the top N entries sorted descending by count.

func (*TopTracker) TopPage

func (t *TopTracker) TopPage(limit, offset int) ([]TopEntry, int)

TopPage returns a paginated top list sorted descending by count.

type UpdateInfo

type UpdateInfo struct {
	CurrentVersion  string `json:"current_version"`
	LatestVersion   string `json:"latest_version"`
	UpdateAvailable bool   `json:"update_available"`
	ReadOnly        bool   `json:"read_only"`
	ReadOnlyHint    string `json:"read_only_hint,omitempty"`
	ReleaseURL      string `json:"release_url,omitempty"`
	ReleaseNotes    string `json:"release_notes,omitempty"`
	AssetName       string `json:"asset_name,omitempty"`
}

UpdateInfo holds information about available updates.

Jump to

Keyboard shortcuts

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