template

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTemplate

func ParseTemplate(id, content string) (*templ.Template, error)

ParseTemplate creates go Template with the given id from the given string content in any error occurs creating the template, an erro is returned

func Render

func Render(template Template, properties map[string]interface{}) (string, error)

Render tries to render a given template with the given properties and returns the resulting string. if any error occurs during rendering, an error is returned.

Types

type DownloadTemplate

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

func (*DownloadTemplate) Content

func (d *DownloadTemplate) Content() string

func (*DownloadTemplate) Id

func (d *DownloadTemplate) Id() string

func (*DownloadTemplate) Name

func (d *DownloadTemplate) Name() string

func (*DownloadTemplate) UpdateContent

func (d *DownloadTemplate) UpdateContent(newContent string)

type FileBasedTemplate

type FileBasedTemplate interface {
	Template
	FilePath() string
}

FileBasedTemplate is the usual (only) type of config template monaco uses This is the usual API payload JSON file

type Template

type Template interface {
	// id of the template, used as a key in the template cache
	Id() string

	// human readable name for this template, mostly used for debugging
	Name() string

	// string content of the template
	Content() string

	// UpdateContent sets the content of the template to the new provided one
	UpdateContent(newContent string)
}

Template is the main interface of a configuration payload that may contain template references (using Go Templates) The only implementation used in monaco is the FilebasedTemplate, but this interface is meant to enable any usecase where the content of a configuration is not coming from a file - e.g. a possible use as a library in a terraform provider, which could implement its own extension of a Template that turns an object in TF configuration language into deployable JSON payload when Content() is called.

func CreateTemplateFromString

func CreateTemplateFromString(path, content string) Template

tries to parse the given string into a template and return it

func LoadTemplate

func LoadTemplate(fs afero.Fs, path string) (Template, error)

tries to load the file at the given path and turns it into a template. the name of the template will be the sanitized path.

func NewDownloadTemplate

func NewDownloadTemplate(id, name, content string) Template

Jump to

Keyboard shortcuts

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