filegen

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 28 Imported by: 12

Documentation

Overview

Package filegen manages the generation of computed files.

Package filegen may be used to implement a computed file server. It registers a FileGenerator server with the lib/srpc package. The application may register multiple file generators.

A generator for the /etc/mdb.json pathname is automatically registered.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileGenerator

type FileGenerator interface {
	Generate(machine mdb.Machine, logger log.Logger) (
		data []byte, validUntil time.Time, err error)
}

FileGenerator is the interface that wraps the Generate method.

Generate computes file data from the provided machine information. The logger may be used to log problems. It returns the data, a time.Time indicating when the data are valid until (a zero time indicates the data are valid forever) and an error.

type Manager

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

func New

func New(logger log.Logger) *Manager

New creates a new *Manager. Only one should be created per application. The logger will be used to log problems.

func (*Manager) GetRegisteredPaths

func (m *Manager) GetRegisteredPaths() []string

GetRegisteredPaths returns a slice of filenames which have generators.

func (*Manager) RegisterFileForPath

func (m *Manager) RegisterFileForPath(pathname string, sourceFile string)

RegisterFileForPath registers a source file for a specific pathname. The source file is used as the data source. If the source file changes, the data are re-read.

func (*Manager) RegisterGeneratorForPath

func (m *Manager) RegisterGeneratorForPath(pathname string,
	gen FileGenerator) chan<- string

RegisterGeneratorForPath registers a FileGenerator for a specific pathname. It returns a channel to which notification messages may be sent indicating that the data should be regenerated, even if the machine data have not changed. If the empty string is sent to the channel, it indicates that data should be regenerated for all machines, otherwise it indicates that data should be regenerated for a specific machine. An internal goroutine reads from the channel, which terminates if the channel is closed. The channel should be closed if the data should only be regenerated if the machine data change.

func (*Manager) RegisterMdbFieldDirectoryForPath added in v0.3.3

func (m *Manager) RegisterMdbFieldDirectoryForPath(pathname string,
	field, directory string, interval time.Duration) error

RegisterMdbFieldDirectoryForPath registers a generator for pathname which yields data from files under the specified directory where the filenames are taken from the specified field of the MDB data for a machine. The data are periodically reloaded every specified interval (if greater than zero).

func (*Manager) RegisterMdbGeneratorForPath

func (m *Manager) RegisterMdbGeneratorForPath(pathname string)

RegisterMdbGeneratorForPath registers a generator for pathname which yields the MDB data in JSON format for a machine.

func (*Manager) RegisterProgrammeForPath added in v0.4.0

func (m *Manager) RegisterProgrammeForPath(pathname, programmePath string)

RegisterProgrammeForPath registers a programme which will be called to generate data for the specified pathname. The pathname will be provided as the first argument to the programme. The MDB data for the machine will be written to the standard input in JSON format. The data and number of seconds it is valid (0 means indefinitely valid) must be written to the standard output in JSON format, stored in the Data and SecondsValid fields.

func (*Manager) RegisterTemplateFileForPath

func (m *Manager) RegisterTemplateFileForPath(pathname string,
	templateFile string, watchForUpdates bool) error

RegisterTemplateFileForPath registers a template file for a specific pathname. The template file is used to generate the data, modified by the machine data. If the template file changes and watchForUpdates is true, the template file is re-read and the data are regenerated. The template file syntax is defined by the text/template standard package.

func (*Manager) RegisterUrlForPath added in v0.4.0

func (m *Manager) RegisterUrlForPath(pathname, URL string)

RegisterUrlForPath registers a URL where a HTTP POST request may be sent to generate data for the specified pathname. The pathname will be provided in a pathname= query parameter. The MDB data for the machine will be written to the message body in JSON format. The data and number of seconds it is valid (0 means indefinitely valid) must be returned in the response body in JSON format, stored in the Data and SecondsValid fields.

func (*Manager) WriteHtml

func (m *Manager) WriteHtml(writer io.Writer)

WriteHtml will write status information about the Manager to w, with appropriate HTML markups.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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