app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 45 Imported by: 0 modules, 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

Overview

Package app is the composition root: it loads the configuration, maps it onto the Settings and Specs of every package and builds all components (Create* factories). Together with cmd it is the only importer of internal/config.

Index

Constants

View Source
const (
	ShutdownDeadline = 30 * time.Second
)

Lifecycle constants (spec 8.3).

Variables

This section is empty.

Functions

func BackupJobDB

func BackupJobDB(ctx context.Context, l *Loaded, db *sql.DB, now time.Time) (string, error)

BackupJobDB makes the verified backup every CLI job needs before writing (spec 7.5) and returns its path.

func CreateAuth

func CreateAuth(l *Loaded, st *storage.Storage, clock util.Clock, log zerolog.Logger,
) (*auth.Service, error)

CreateAuth builds the auth service from auth.* (server and CLI jobs).

func CreateConfigStore

func CreateConfigStore(l *Loaded, st *storage.Storage, clock util.Clock, create bool,
) (*configstore.Service, error)

CreateConfigStore builds the config service; create makes secret.key when missing (server), CLI jobs read without creating it.

func CreateFetcher

func CreateFetcher(s *site.Site, d *site.Device, mb *modbus.Conn, clock util.Clock,
	log zerolog.Logger,
) (*collector.Fetcher, error)

CreateFetcher builds the raw fetcher of a device on a started Modbus connection (nil for HTTP devices) or with a new HTTP client.

func CreateHTTPClient

func CreateHTTPClient(c *site.Connection, d *site.Device, clock util.Clock, log zerolog.Logger,
) (*httpt.Client, error)

CreateHTTPClient builds the HTTP transport of one device.

func CreateLogger

func CreateLogger(stdout io.Writer, l *Loaded) (*logging.Logger, error)

CreateLogger builds the logger from app.log_level and log.*.

func CreateModbusConn

func CreateModbusConn(c *site.Connection, clock util.Clock, log zerolog.Logger,
) (*modbus.Conn, error)

CreateModbusConn builds the shared connection of a tcp:// or rtu:// address.

func IsModbus

func IsModbus(c *site.Connection) bool

IsModbus reports whether a connection uses Modbus.

func LocalLocation

func LocalLocation() *time.Location

LocalLocation returns the server time zone under its IANA name (spec 2: the time zone comes only from TZ). time.Local itself is named "Local", which the UI cannot use.

func OpenJobDB

func OpenJobDB(ctx context.Context, l *Loaded, now time.Time) (*sql.DB, error)

OpenJobDB opens and migrates the database of a "stopped" CLI job; the caller holds the exclusive lock and closes the database.

func RealProbe

func RealProbe(s *site.Site, d *site.Device, bus collector.Transport, clock util.Clock,
	log zerolog.Logger,
) (collector.Source, func(), error)

RealProbe reads through the running collector's Modbus connection, so a probe never opens a second client on the same bus (AGENTS.md section 7). Only an address no collector serves yet gets a connection of its own for the probe; HTTP devices get a fresh client.

func RealSources

func RealSources(s *site.Site, c *site.Connection, clock util.Clock, log zerolog.Logger,
) (map[string]collector.Source, collector.Transport, error)

RealSources builds fetchers on the real transports of a connection.

func Serve

func Serve(ctx context.Context, o ServeOptions) error

Serve runs the server until ctx ends (exit 0) or a fatal health error (ErrHealthFatal).

Types

type Loaded

type Loaded struct {
	Result *config.Result
	Site   *site.Site
	// contains filtered or unexported fields
}

Loaded is the validated configuration with the site built from it.

func LoadConfig

func LoadConfig(src config.Source, builtin fs.FS) (*Loaded, error)

LoadConfig loads the layered configuration and builds the site; the site rules run as config.Rules so every problem is reported at once with its path.

func LoadStored

func LoadStored(ctx context.Context, l *Loaded, clock util.Clock) (*Loaded, error)

LoadStored returns l with the UI configuration stored in its database, opened read-only so it works while the server runs. Without a database file l is returned.

func (*Loaded) WithDB

func (l *Loaded) WithDB(layer map[string]any, rev int64) (*Loaded, error)

WithDB loads the same file and env layers again over the UI configuration layer of revision rev (spec 3: defaults → DB → file → env). Relative profile paths of devices from the UI layer are resolved against the data directory (spec 4.5).

type ProbeFactory

type ProbeFactory func(s *site.Site, d *site.Device, bus collector.Transport, clock util.Clock,
	log zerolog.Logger) (src collector.Source, release func(), err error)

ProbeFactory builds a one-shot source for device d of a draft site. bus is the transport of the collector running on d's connection, nil when none runs; release ends whatever the source opened itself.

type ServeOptions

type ServeOptions struct {
	Loaded   *Loaded
	Build    buildinfo.Info
	Stdout   io.Writer
	Listen   func(addr string) (net.Listener, error)
	Clock    util.Clock
	Sources  SourceFactory
	Probe    ProbeFactory
	Location *time.Location
}

ServeOptions configure Serve; zero Listen, Clock, Sources and Probe use the real ones.

type SourceFactory

type SourceFactory func(s *site.Site, c *site.Connection, clock util.Clock, log zerolog.Logger,
) (map[string]collector.Source, collector.Transport, error)

SourceFactory builds the sources and transport of one connection's collector.

Jump to

Keyboard shortcuts

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