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 ¶
- type FileGenerator
- type Manager
- func (m *Manager) GetRegisteredPaths() []string
- func (m *Manager) RegisterFileForPath(pathname string, sourceFile string)
- func (m *Manager) RegisterGeneratorForPath(pathname string, gen FileGenerator) chan<- string
- func (m *Manager) RegisterMdbGeneratorForPath(pathname string)
- func (m *Manager) RegisterTemplateFileForPath(pathname string, templateFile string, watchForUpdates bool) error
- func (m *Manager) WriteHtml(writer io.Writer)
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 ¶
New creates a new *Manager. Only one should be created per application. The logger will be used to log problems.
func (*Manager) GetRegisteredPaths ¶
GetRegisteredPaths returns a slice of filenames which have generators.
func (*Manager) RegisterFileForPath ¶
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) RegisterMdbGeneratorForPath ¶
RegisterMdbGeneratorForPath registers a generator for pathname which yields the MDB data in JSON format for a machine.
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.