format

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 5 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

This section is empty.

Variables

This section is empty.

Functions

func SortKeys added in v0.4.0

func SortKeys(keys []string, path []interface{}) []string

SortKeys sorts the given keys based on their location within a CloudFormation template as given by the path parameter

Types

type Formatter

type Formatter struct {
	Options Options
}

func New added in v0.6.0

func New(options Options) 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

type Options added in v0.6.0

type Options struct {
	Style   Style
	Compact bool
}

type Style added in v0.6.0

type Style int
const (
	YAML Style = iota
	JSON
)

Jump to

Keyboard shortcuts

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