files

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package files provides templating functions based on github.com/helm/helm/pkg/chartutil/files.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJson

func FromJson(str string) map[string]interface{}

FromJson converts a JSON document into a map[string]interface{}.

This is not a general-purpose JSON parser, and will not parse all valid JSON documents. Additionally, because its intended use is within templates it tolerates errors. It will insert the returned error message string into m["Error"] in the returned map.

func FromYaml

func FromYaml(str string) map[string]interface{}

FromYaml converts a YAML document into a map[string]interface{}.

This is not a general-purpose YAML parser, and will not parse all valid YAML documents. Additionally, because its intended use is within templates it tolerates errors. It will insert the returned error message string into m["Error"] in the returned map.

func ToJson

func ToJson(v interface{}) string

ToJson takes an interface, marshals it to json, and returns a string. It will always return a string, even on marshal error (empty string).

This is designed to be called from a template.

func ToToml

func ToToml(v interface{}) string

ToToml takes an interface, marshals it to toml, and returns a string. It will always return a string, even on marshal error (empty string).

This is designed to be called from a template.

func ToYaml

func ToYaml(v interface{}) string

ToYaml takes an interface, marshals it to yaml, and returns a string. It will always return a string, even on marshal error (empty string).

This is designed to be called from a template.

Types

type Dir

type Dir string

Dir is the path to load relative files from.

func (Dir) Get

func (dir Dir) Get(name string) string

Get returns a string representation of the given file.

Fetch the contents of a file as a string. It is designed to be called in a template.

{{.Files.Get "foo"}}

func (Dir) Glob

func (dir Dir) Glob(pattern string) Files

Glob takes a glob pattern and returns another files object only containing matched files.

This is designed to be called from a template.

{{ range $name, $content := .Files.Glob("foo/**") }} {{ $name }}: | {{ .Files.Get($name) | indent 4 }}{{ end }}

type Files

type Files map[string]string

Files is a map of files in a chart that can be accessed from a template.

func (Files) AsConfig

func (f Files) AsConfig() string

AsConfig turns a Files group and flattens it to a YAML map suitable for including in the 'data' section of a Kubernetes ConfigMap definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.

This is designed to be called from a template, and will return empty string (via ToYaml function) if it cannot be serialized to YAML, or if the Files object is nil.

The output will not be indented, so you will want to pipe this to the 'indent' template function.

data:

{{ (.Files.Glob "config/**").AsConfig() | indent 4 }}

func (Files) AsSecrets

func (f Files) AsSecrets() string

AsSecrets returns the base64-encoded value of a Files object suitable for including in the 'data' section of a Kubernetes Secret definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.

This is designed to be called from a template, and will return empty string (via ToYaml function) if it cannot be serialized to YAML, or if the Files object is nil.

The output will not be indented, so you will want to pipe this to the 'indent' template function.

data:

{{ (.Files.Glob "secrets/*").AsSecrets() }}

Jump to

Keyboard shortcuts

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