facts

package
v0.0.0-...-453cd44 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 6 Imported by: 9

Documentation

Overview

Package facts provides a framework for language values that change over time.

Index

Constants

This section is empty.

Variables

View Source
var RegisteredFacts = make(map[string]func() Fact) // must initialize

RegisteredFacts is a global map of all possible facts which can be used. You should never touch this map directly. Use methods like Register instead.

Functions

func ModuleRegister

func ModuleRegister(module, name string, fn func() Fact)

ModuleRegister is exactly like Register, except that it registers within a named module. This is a helper function.

func Register

func Register(name string, fn func() Fact)

Register takes a fact and its name and makes it available for use. It is commonly called in the init() method of the fact at program startup. There is no matching Unregister function.

Types

type Fact

type Fact interface {
	String() string
	//Validate() error // currently not needed since no facts are internal
	Info() *Info
	Init(*Init) error
	Stream(context.Context) error
}

Fact is the interface that any valid fact must fulfill. It is very simple, but still event driven. Facts should attempt to only send values when they have changed. TODO: should we support a static version of this interface for facts that never change to avoid the overhead of the goroutine and channel listener? TODO: should we move this to the interface package?

type FactFunc

type FactFunc struct {
	Fact Fact
}

FactFunc is a wrapper for the fact interface. It implements the fact interface in terms of Func to reduce the two down to a single mechanism.

func (*FactFunc) Info

func (obj *FactFunc) Info() *interfaces.Info

Info returns some static info about itself.

func (*FactFunc) Init

func (obj *FactFunc) Init(init *interfaces.Init) error

Init runs some startup code for this fact.

func (*FactFunc) Stream

func (obj *FactFunc) Stream(ctx context.Context) error

Stream returns the changing values that this function has over time.

func (*FactFunc) String

func (obj *FactFunc) String() string

String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.

func (*FactFunc) Validate

func (obj *FactFunc) Validate() error

Validate makes sure we've built our struct properly.

type Info

type Info struct {
	Output *types.Type // output value type (must not change over time!)
	Err    error       // did this fact validate?
}

Info is a static representation of some information about the fact. It is used for static analysis and type checking. If you break this contract, you might cause a panic.

type Init

type Init struct {
	Hostname string // uuid for the host
	//Noop bool
	Output chan types.Value // Stream must close `output` chan
	World  engine.World
	Debug  bool
	Logf   func(format string, v ...interface{})
}

Init is the structure of values and references which is passed into all facts on initialization.

Jump to

Keyboard shortcuts

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