pulumi/pkg/encoding/marshal.go
joeduffy 1302fc8a47 Add rudimentary template expansion
This change performs template expansion both for root stack documents in
addition to the transitive closure of dependencies.  There are many ongoing
design and implementation questions about how this should actually work;
please see marapongo/mu#7 for a discussion of them.
2016-11-25 12:58:29 -08:00

57 lines
1.6 KiB
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package encoding
import (
"encoding/json"
"github.com/ghodss/yaml"
)
// Exts contains a list of all the valid marshalable extension types.
var Exts = []string{
".json",
".yaml",
// Although ".yml" is not a sanctioned YAML extension, it is used quite broadly; so we will support it.
".yml",
}
// Marshalers is a map of extension to a Marshaler object for that extension.
var Marshalers map[string]Marshaler
// Marshaler is a type that knows how to marshal and unmarshal data in one format.
type Marshaler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
var JSON Marshaler = &jsonMarshaler{}
type jsonMarshaler struct {
}
func (m *jsonMarshaler) Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
func (m *jsonMarshaler) Unmarshal(data []byte, v interface{}) error {
// TODO: use a "strict" marshaler, so that we can warn on unrecognized keys (avoiding silly mistakes). We should
// set aside an officially sanctioned area in the metadata for extensibility by 3rd parties.
return json.Unmarshal(data, v)
}
var YAML Marshaler = &yamlMarshaler{}
type yamlMarshaler struct {
}
func (m *yamlMarshaler) Marshal(v interface{}) ([]byte, error) {
return yaml.Marshal(v)
}
func (m *yamlMarshaler) Unmarshal(data []byte, v interface{}) error {
// TODO: use a "strict" marshaler, so that we can warn on unrecognized keys (avoiding silly mistakes). We should
// set aside an officially sanctioned area in the metadata for extensibility by 3rd parties.
return yaml.Unmarshal(data, v)
}