package coreexample

import "github.com/purpleidea/mgmt/lang/core/example"

Index

Constants

const Answer = 42

Answer is the Answer to Life, the Universe and Everything.

const (
	// FlipFlopFuncName is the name this fact is registered as. It's still a
	// Func Name because this is the name space the fact is actually using.
	FlipFlopFuncName = "flipflop"
)
const (
	// ModuleName is the prefix given to all the functions in this module.
	ModuleName = "example"
)
const (
	// VUMeterFuncName is the name this function is registered as.
	VUMeterFuncName = "vumeter"
)

Functions

func ErrorBool

func ErrorBool(ctx context.Context, input []types.Value) (types.Value, error)

ErrorBool causes this function to error if you pass it true. Otherwise it returns a string reminding you how to use it.

func Int2Str

func Int2Str(ctx context.Context, input []types.Value) (types.Value, error)

Int2Str takes an int, and returns it as a string.

func Plus

func Plus(ctx context.Context, input []types.Value) (types.Value, error)

Plus returns y + z.

func Str2Int

func Str2Int(ctx context.Context, input []types.Value) (types.Value, error)

Str2Int takes an str, and returns it as an int. If it can't convert it, it returns 0.

func TheAnswerToLifeTheUniverseAndEverything

func TheAnswerToLifeTheUniverseAndEverything(context.Context, []types.Value) (types.Value, error)

TheAnswerToLifeTheUniverseAndEverything returns the Answer to Life, the Universe and Everything.

Types

type FlipFlopFact

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

FlipFlopFact is a fact which flips a bool repeatedly. This is an example fact and is not meant for serious computing. This would be better served by a flip function which you could specify an interval for.

func (*FlipFlopFact) Call

func (obj *FlipFlopFact) Call(ctx context.Context) (types.Value, error)

Call this fact and return the value if it is possible to do so at this time.

func (*FlipFlopFact) Info

func (obj *FlipFlopFact) Info() *facts.Info

Info returns some static info about itself.

func (*FlipFlopFact) Init

func (obj *FlipFlopFact) Init(init *facts.Init) error

Init runs some startup code for this fact.

func (*FlipFlopFact) Stream

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

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

func (*FlipFlopFact) String

func (obj *FlipFlopFact) String() string

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

type VUMeterFunc

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

VUMeterFunc is a gimmic function to display a vu meter from the microphone.

func (*VUMeterFunc) ArgGen

func (obj *VUMeterFunc) ArgGen(index int) (string, error)

ArgGen returns the Nth arg name for this function.

func (*VUMeterFunc) Call

func (obj *VUMeterFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)

Call this function with the input args and return the value if it is possible to do so at this time.

func (*VUMeterFunc) Info

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

Info returns some static info about itself.

func (*VUMeterFunc) Init

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

Init runs some startup code for this function.

func (*VUMeterFunc) Stream

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

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

func (*VUMeterFunc) String

func (obj *VUMeterFunc) String() string

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

func (*VUMeterFunc) Validate

func (obj *VUMeterFunc) Validate() error

Validate makes sure we've built our struct properly. It is usually unused for normal functions that users can use directly.

Source Files

answer.go errorbool.go example.go flipflop_fact.go int2str.go plus.go str2int.go vumeter.go

Directories

PathSynopsis
lang/core/example/nested
Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
16 packages
Last checked
4 days ago

Tools for package owners.