Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YAMLToJSONCustom to accept custom unmarshal func #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// See also http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang
//
package yaml // import "github.com/ghodss/yaml"
package yaml // import "github.com/ghodss/yaml"

import (
"bytes"
Expand Down Expand Up @@ -123,6 +123,12 @@ func YAMLToJSONStrict(y []byte) ([]byte, error) {
return yamlToJSON(y, nil, yaml.UnmarshalStrict)
}

// YAMLToJSONCustom is like YAMLToJSON but uses the passed in function to
// unmarshal from YAML to an object.
func YAMLToJSONCustom(y []byte, yamlUnmarshal func([]byte, interface{}) error) ([]byte, error) {
return yamlToJSON(y, nil, yamlUnmarshal)
}

func yamlToJSON(y []byte, jsonTarget *reflect.Value, yamlUnmarshal func([]byte, interface{}) error) ([]byte, error) {
// Convert the YAML to an object.
var yamlObj interface{}
Expand Down