template

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 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 FileBasedTemplate

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

FileBasedTemplate is a JSON Template stored in a file - when it's Template.Content is accessed, that file is read. This is the usual type of Template monaco uses.

func (*FileBasedTemplate) Content added in v2.9.1

func (t *FileBasedTemplate) Content() (string, error)

func (*FileBasedTemplate) FilePath

func (t *FileBasedTemplate) FilePath() string

func (*FileBasedTemplate) ID added in v2.9.1

func (t *FileBasedTemplate) ID() string

func (*FileBasedTemplate) UpdateContent added in v2.9.1

func (t *FileBasedTemplate) UpdateContent(newContent string) error

type InMemoryTemplate added in v2.9.1

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

InMemoryTemplate is a JSON Template created in-memory. This is generally used by downloads and conversions, where a Template is created on the fly. Deployments generally use FileBasedTemplate instead. An InMemoryTemplate may define a dedicated path to write it to when persisting - converted Template are create with a path, download ones are not.

func (*InMemoryTemplate) Content added in v2.9.1

func (t *InMemoryTemplate) Content() (string, error)

func (*InMemoryTemplate) FilePath added in v2.9.1

func (t *InMemoryTemplate) FilePath() *string

FilePath returns the optional path this Template should be written to if it's persisted. If an InMemoryTemplate has not defined a path nil will be returned and the file may be persisted anywhere. Generally a converted v1 Template will have a defined FilePath, while a downloaded template does not.

func (*InMemoryTemplate) ID added in v2.9.1

func (t *InMemoryTemplate) ID() string

func (*InMemoryTemplate) UpdateContent added in v2.9.1

func (t *InMemoryTemplate) UpdateContent(newContent string) error

type Template

type Template interface {
	// ID is a unique identifier for this template. It should be usable in user-facing messages.
	ID() string

	// Content returns the string content of the template, returns error if content is not accessible.
	Content() (string, error)

	// UpdateContent sets the content of the template to the new provided one, returns error if update failed.
	UpdateContent(newContent string) error
}

Template is the main interface of a configuration payload that may contain template references (using Go Templates) The main implementation is FileBasedTemplate, which loads its Content from a file on disk. An InMemoryTemplate exists as well and is used in cases where Template data is not related to a file - e.g. during download or convert.

func NewFileTemplate added in v2.9.1

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

NewFileTemplate creates a FileBasedTemplate for a given afero.Fs and filepath. If the file can not be accessed an error will be returned.

func NewInMemoryTemplate added in v2.9.1

func NewInMemoryTemplate(id, content string) Template

NewInMemoryTemplate creates a new InMemoryTemplate without a dedicated path it should be written to if persisted. To create an InMemoryTemplate with a fixed target path, use NewInMemoryTemplateWithPath.

func NewInMemoryTemplateWithPath added in v2.9.1

func NewInMemoryTemplateWithPath(filepath, content string) Template

NewInMemoryTemplateWithPath creates a new InMemoryTemplate with a dedicated path it should be written to if persisted. To create a simple InMemoryTemplate without filepath, use NewInMemoryTemplate.

Jump to

Keyboard shortcuts

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