gf/encoding/gyaml/gyaml.go

31 lines
816 B
Go
Raw Normal View History

// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2019-01-15 23:27:47 +08:00
// Package gyaml provides accessing and converting for YAML content.
package gyaml
2019-07-29 21:01:19 +08:00
import "github.com/gogf/gf/internal/thirdparty/github.com/ghodss/yaml"
func Encode(v interface{}) ([]byte, error) {
2019-06-19 09:06:52 +08:00
return yaml.Marshal(v)
}
func Decode(v []byte) (interface{}, error) {
2019-06-19 09:06:52 +08:00
var result interface{}
if err := yaml.Unmarshal(v, &result); err != nil {
return nil, err
}
return result, nil
}
func DecodeTo(v []byte, result interface{}) error {
2019-06-19 09:06:52 +08:00
return yaml.Unmarshal(v, &result)
}
func ToJson(v []byte) ([]byte, error) {
2019-06-19 09:06:52 +08:00
return yaml.YAMLToJSON(v)
}