pulumi/pkg/schema/marshal.go
joeduffy 79f5f312b8 Support .yml Mufile extensions
This change recognizes .yml in addition to the official .yaml extension,
since .yml is actually very commonly used.  In addition, while in here, I've
centralized more of the extensions logic so that it's more "data-driven"
and easier to manage down the road (one place to change rather than two).
2016-11-15 18:26:21 -08:00

38 lines
781 B
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package schema
import (
"encoding/json"
"github.com/ghodss/yaml"
)
// 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
}
type jsonMarshaler struct {
}
func (m *jsonMarshaler) Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
func (m *jsonMarshaler) Unmarshal(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
type yamlMarshaler struct {
}
func (m *yamlMarshaler) Marshal(v interface{}) ([]byte, error) {
return yaml.Marshal(v)
}
func (m *yamlMarshaler) Unmarshal(data []byte, v interface{}) error {
return yaml.Unmarshal(data, v)
}