2019-02-02 16:18:25 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-01-19 16:19:48 +08:00
|
|
|
//
|
|
|
|
// 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,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-01-19 16:19:48 +08:00
|
|
|
|
2019-01-15 23:27:47 +08:00
|
|
|
// Package gyaml provides accessing and converting for YAML content.
|
2018-01-19 16:19:48 +08:00
|
|
|
package gyaml
|
|
|
|
|
2019-02-02 16:18:25 +08:00
|
|
|
import "github.com/gogf/gf/third/github.com/ghodss/yaml"
|
2018-01-19 16:19:48 +08:00
|
|
|
|
|
|
|
func Encode(v interface{}) ([]byte, error) {
|
|
|
|
return yaml.Marshal(v)
|
|
|
|
}
|
|
|
|
|
2018-01-20 11:09:27 +08:00
|
|
|
func Decode(v []byte) (interface{}, error) {
|
2018-01-19 16:19:48 +08:00
|
|
|
var result interface{}
|
2018-01-20 11:09:27 +08:00
|
|
|
if err := yaml.Unmarshal(v, &result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result, nil
|
2018-01-19 16:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeTo(v []byte, result interface{}) error {
|
|
|
|
return yaml.Unmarshal(v, &result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ToJson(v []byte) ([]byte, error) {
|
|
|
|
return yaml.YAMLToJSON(v)
|
|
|
|
}
|