提交 cda23f29 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Add format function

上级 68803624
package cmd
import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
)
type OutputOption struct {
Format string
}
const (
JsonOutputFormat string = "json"
YAMLOutputFormat string = "yaml"
)
func Format(obj interface{}, format string) (data []byte, err error) {
if format == JsonOutputFormat {
return json.MarshalIndent(obj, "", " ")
} else if format == YAMLOutputFormat {
return yaml.Marshal(obj)
}
return nil, fmt.Errorf("not support format %s", format)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册