format

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package format provides functions for formatting CloudFormation templates using an opinionated, idiomatic format as used in AWS documentation.

For each function, CloudFormation templates should be represented using a map[string]interface{} as output by other libraries that parse JSON/YAML such as github.com/awslabs/goformation and encoding/json.

Comments can be passed along with the template data in the following format:

map[interface{}]interface{}{
	"": "This is a top-level comment",
	"Resources": map[interface{}]interface{}{
		"": "This is a comment on the whole `Resources` property",
		"MyBucket": map[interface{}]interface{}{
			"Properties": map[interface{}]interface{}{
				"BucketName": "This is a comment on BucketName",
			},
		},
	},
}

Empty string keys are taken to represent a comment on the overall node that the comment is attached to. Numeric keys can be used to reference elements of arrays in the source data.

Index

Constants

View Source
const (
	YAML = iota
	JSON
)

Variables

This section is empty.

Functions

func Json

func Json(data interface{}) string

Json formats the CloudFormation template as a Json string

func JsonWithComments

func JsonWithComments(data interface{}, comments map[interface{}]interface{}) string

JsonWithComments formats the CloudFormation template as a Json string with comments as provided

func Yaml

func Yaml(data interface{}) string

Yaml formats the CloudFormation template as a Yaml string

func YamlWithComments

func YamlWithComments(data interface{}, comments map[interface{}]interface{}) string

YamlWithComments formats the CloudFormation template as a Yaml string with comments as provided

Types

type Formatter

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

func NewFormatter

func NewFormatter() Formatter

func (*Formatter) Format

func (f *Formatter) Format(data interface{}) string

func (*Formatter) FormatWithComments

func (f *Formatter) FormatWithComments(data interface{}, comments map[interface{}]interface{}) string

func (*Formatter) SetCompact

func (f *Formatter) SetCompact()

func (*Formatter) SetExpanded

func (f *Formatter) SetExpanded()

func (*Formatter) SetJSON

func (f *Formatter) SetJSON()

func (*Formatter) SetYAML

func (f *Formatter) SetYAML()

Jump to

Keyboard shortcuts

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