2019-05-08 22:04:36 +08:00
|
|
|
// 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://gitee.com/johng/gp.
|
|
|
|
|
|
|
|
package gparser
|
|
|
|
|
2019-12-12 11:40:23 +08:00
|
|
|
// ========================================================================
|
|
|
|
// JSON
|
|
|
|
// ========================================================================
|
2019-05-08 22:04:36 +08:00
|
|
|
|
|
|
|
func VarToJson(value interface{}) ([]byte, error) {
|
2019-06-19 09:06:52 +08:00
|
|
|
return New(value).ToJson()
|
2019-05-08 22:04:36 +08:00
|
|
|
}
|
|
|
|
|
2019-05-11 17:56:14 +08:00
|
|
|
func VarToJsonString(value interface{}) (string, error) {
|
|
|
|
return New(value).ToJsonString()
|
|
|
|
}
|
|
|
|
|
2019-05-08 22:04:36 +08:00
|
|
|
func VarToJsonIndent(value interface{}) ([]byte, error) {
|
2019-05-11 17:56:14 +08:00
|
|
|
return New(value).ToJsonIndent()
|
|
|
|
}
|
|
|
|
|
|
|
|
func VarToJsonIndentString(value interface{}) (string, error) {
|
|
|
|
return New(value).ToJsonIndentString()
|
2019-05-08 22:04:36 +08:00
|
|
|
}
|
|
|
|
|
2019-12-12 11:40:23 +08:00
|
|
|
func MustToJson(value interface{}) []byte {
|
|
|
|
return New(value).MustToJson()
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustToJsonString(value interface{}) string {
|
|
|
|
return New(value).MustToJsonString()
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustToJsonIndent(value interface{}) []byte {
|
|
|
|
return New(value).MustToJsonIndent()
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustToJsonIndentString(value interface{}) string {
|
|
|
|
return New(value).MustToJsonIndentString()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// XML
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
func VarToXml(value interface{}, rootTag ...string) ([]byte, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").ToXml(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func VarToXmlString(value interface{}, rootTag ...string) (string, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").ToXmlString(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func VarToXmlIndent(value interface{}, rootTag ...string) ([]byte, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").ToXmlIndent(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func VarToXmlIndentString(value interface{}, rootTag ...string) (string, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").ToXmlIndentString(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToXml(value interface{}, rootTag ...string) []byte {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").MustToXml(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToXmlString(value interface{}, rootTag ...string) string {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").MustToXmlString(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToXmlIndent(value interface{}, rootTag ...string) []byte {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").MustToXmlIndent(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToXmlIndentString(value interface{}, rootTag ...string) string {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "xml").MustToXmlIndentString(rootTag...)
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// YAML
|
|
|
|
// ========================================================================
|
|
|
|
|
2019-05-08 22:04:36 +08:00
|
|
|
func VarToYaml(value interface{}) ([]byte, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "yaml").ToYaml()
|
2019-05-08 22:04:36 +08:00
|
|
|
}
|
|
|
|
|
2019-12-12 11:40:23 +08:00
|
|
|
func VarToYamlString(value interface{}) (string, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "yaml").ToYamlString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToYaml(value interface{}) []byte {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "yaml").MustToYaml()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToYamlString(value interface{}) string {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "yaml").MustToYamlString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// TOML
|
|
|
|
// ========================================================================
|
|
|
|
|
2019-05-08 22:04:36 +08:00
|
|
|
func VarToToml(value interface{}) ([]byte, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "toml").ToToml()
|
2019-05-08 22:04:36 +08:00
|
|
|
}
|
2019-08-12 16:53:07 +08:00
|
|
|
|
2019-12-12 11:40:23 +08:00
|
|
|
func VarToTomlString(value interface{}) (string, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "toml").ToTomlString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToToml(value interface{}) []byte {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "toml").MustToToml()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToTomlString(value interface{}) string {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "toml").MustToTomlString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// INI
|
|
|
|
// ========================================================================
|
|
|
|
|
2019-08-12 16:53:07 +08:00
|
|
|
func VarToIni(value interface{}) ([]byte, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "ini").ToIni()
|
2019-08-12 16:53:07 +08:00
|
|
|
}
|
2019-12-12 11:40:23 +08:00
|
|
|
|
|
|
|
func VarToIniString(value interface{}) (string, error) {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "ini").ToIniString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToIni(value interface{}) []byte {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "ini").MustToIni()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustToIniString(value interface{}) string {
|
2020-02-08 14:07:32 +08:00
|
|
|
return NewWithTag(value, "ini").MustToIniString()
|
2019-12-12 11:40:23 +08:00
|
|
|
}
|