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
- func BackupJobDB(ctx context.Context, l *Loaded, db *sql.DB, now time.Time) (string, error)
- func CreateAuth(l *Loaded, st *storage.Storage, clock util.Clock, log zerolog.Logger) (*auth.Service, error)
- func CreateConfigStore(l *Loaded, st *storage.Storage, clock util.Clock, create bool) (*configstore.Service, error)
- func CreateFetcher(s *site.Site, d *site.Device, mb *modbus.Conn, clock util.Clock, ...) (*collector.Fetcher, error)
- func CreateHTTPClient(c *site.Connection, d *site.Device, clock util.Clock, log zerolog.Logger) (*httpt.Client, error)
- func CreateLogger(stdout io.Writer, l *Loaded) (*logging.Logger, error)
- func CreateModbusConn(c *site.Connection, clock util.Clock, log zerolog.Logger) (*modbus.Conn, error)
- func IsModbus(c *site.Connection) bool
- func LocalLocation() *time.Location
- func OpenJobDB(ctx context.Context, l *Loaded, now time.Time) (*sql.DB, error)
- func RealProbe(s *site.Site, d *site.Device, bus collector.Transport, clock util.Clock, ...) (collector.Source, func(), error)
- func RealSources(s *site.Site, c *site.Connection, clock util.Clock, log zerolog.Logger) (map[string]collector.Source, collector.Transport, error)
- func Serve(ctx context.Context, o ServeOptions) error
- type Loaded
- type ProbeFactory
- type ServeOptions
- type SourceFactory
Constants ¶
const (
ShutdownDeadline = 30 * time.Second
)
Lifecycle constants (spec 8.3).
Variables ¶
This section is empty.
Functions ¶
func BackupJobDB ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
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.
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.