package coregolang

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

Index

Constants

const (
	// TemplateFuncName is the name this function is registered as.
	TemplateFuncName = "template"

	// TemplateName is the name of our template as required by the template
	// library.
	TemplateName = "template"
)
const (
	// ModuleName is the prefix given to all the functions in this module.
	ModuleName = "golang"
)

Types

type TemplateFunc

type TemplateFunc struct {
	// Type is the type of the input vars (2nd) arg if one is specified. Nil
	// is the special undetermined value that is used before type is known.
	Type *types.Type // type of vars
	// contains filtered or unexported fields
}

TemplateFunc is a static polymorphic function that compiles a template and returns the output as a string. It bases its output on the values passed in to it. It examines the type of the second argument (the input data vars) at compile time and then determines the static functions signature by including that in the overall signature. TODO: We *might* need to add events for internal function changes over time, but only if they are not pure. We currently only use simple, pure functions.

func (*TemplateFunc) ArgGen

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

ArgGen returns the Nth arg name for this function.

func (*TemplateFunc) Build

func (obj *TemplateFunc) Build(typ *types.Type) (*types.Type, error)

Build takes the now known function signature and stores it so that this function can appear to be static. It extracts the type of the vars argument, which is the dynamic part which can change. That type is used to build our function statically.

func (*TemplateFunc) Call

func (obj *TemplateFunc) 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 (*TemplateFunc) FuncInfer

func (obj *TemplateFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)

FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.

func (*TemplateFunc) Info

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

Info returns some static info about itself.

func (*TemplateFunc) Init

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

Init runs some startup code for this function.

func (*TemplateFunc) Stream

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

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

func (*TemplateFunc) String

func (obj *TemplateFunc) String() string

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

func (*TemplateFunc) Validate

func (obj *TemplateFunc) 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

golang.go template.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
11 packages
Last checked
4 days ago

Tools for package owners.