templatemanager

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CueManager

type CueManager interface {
	// Format - format the cue string, it gets same result of running `cue fmt xxx.cue`
	Format(src []byte, opts ...format.Option) (result []byte, err error)
	// Validate - check the cue whether valid or not, it returns error if it's invalid
	// Same as running `cue vet xxx.cue -c`
	Validate(src []byte, opts ...cue.Option) error
	// DryRun - calculate/render cue with given data.
	// Same as running `cue eval xxx.cue`
	DryRun(src []byte, data any, outputField string) (result []byte, err error)
	// Exec -  execute cue with given data
	Exec(src []byte, data any, outputField string, output any) error
}

CueManager defines methods of manage cue string, it provides various methods tomake sure the cue is valid.

func NewCueManager

func NewCueManager() CueManager

NewCueManager init a new CueManager

type TemplateManager

type TemplateManager interface {
	// Render - render go template with giver data and return result of render and an error
	Render(data any) (result []byte, err error)
}

TemplateManager defines cue rules inside go templates which render the template to valid cue rule.

func NewOverrideTemplateManager

func NewOverrideTemplateManager(ts *TemplateSource) (TemplateManager, error)

NewOverrideTemplateManager init override policy template manager.

func NewTemplateManager

func NewTemplateManager(ts *TemplateSource, funcMap template.FuncMap) (tm TemplateManager, err error)

NewTemplateManager init a manager based on given parameters.

func NewValidateTemplateManager

func NewValidateTemplateManager(ts *TemplateSource) (TemplateManager, error)

NewValidateTemplateManager init validate policy template manager

type TemplateSource

type TemplateSource struct {
	// example: xx/xxx/*.tmpl
	PathPattern string
	// example: xx/xx/yy.tmpl
	FilePath string
	// also can set template content via this field
	Content string
	// TemplateName name of template, if using multi defined template then must specify template name.
	TemplateName string
}

TemplateSource sets template source content, users can set single file path, pattern for multi files or

body of file content. But only can set one of three fields, if there are more than one field be set then will use
the first one only.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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