filegen

package
v0.0.0-...-d8f7d12 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

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) 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) 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) 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