github.com/gogf/gf@v1.16.9/encoding/gparser/gparser_api_encoding.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://gitee.com/johng/gp.
     6  
     7  package gparser
     8  
     9  // ========================================================================
    10  // JSON
    11  // ========================================================================
    12  
    13  func VarToJson(value interface{}) ([]byte, error) {
    14  	return New(value).ToJson()
    15  }
    16  
    17  func VarToJsonString(value interface{}) (string, error) {
    18  	return New(value).ToJsonString()
    19  }
    20  
    21  func VarToJsonIndent(value interface{}) ([]byte, error) {
    22  	return New(value).ToJsonIndent()
    23  }
    24  
    25  func VarToJsonIndentString(value interface{}) (string, error) {
    26  	return New(value).ToJsonIndentString()
    27  }
    28  
    29  func MustToJson(value interface{}) []byte {
    30  	return New(value).MustToJson()
    31  }
    32  
    33  func MustToJsonString(value interface{}) string {
    34  	return New(value).MustToJsonString()
    35  }
    36  
    37  func MustToJsonIndent(value interface{}) []byte {
    38  	return New(value).MustToJsonIndent()
    39  }
    40  
    41  func MustToJsonIndentString(value interface{}) string {
    42  	return New(value).MustToJsonIndentString()
    43  }
    44  
    45  // ========================================================================
    46  // XML
    47  // ========================================================================
    48  
    49  func VarToXml(value interface{}, rootTag ...string) ([]byte, error) {
    50  	return NewWithTag(value, "xml").ToXml(rootTag...)
    51  }
    52  
    53  func VarToXmlString(value interface{}, rootTag ...string) (string, error) {
    54  	return NewWithTag(value, "xml").ToXmlString(rootTag...)
    55  }
    56  
    57  func VarToXmlIndent(value interface{}, rootTag ...string) ([]byte, error) {
    58  	return NewWithTag(value, "xml").ToXmlIndent(rootTag...)
    59  }
    60  
    61  func VarToXmlIndentString(value interface{}, rootTag ...string) (string, error) {
    62  	return NewWithTag(value, "xml").ToXmlIndentString(rootTag...)
    63  }
    64  
    65  func MustToXml(value interface{}, rootTag ...string) []byte {
    66  	return NewWithTag(value, "xml").MustToXml(rootTag...)
    67  }
    68  
    69  func MustToXmlString(value interface{}, rootTag ...string) string {
    70  	return NewWithTag(value, "xml").MustToXmlString(rootTag...)
    71  }
    72  
    73  func MustToXmlIndent(value interface{}, rootTag ...string) []byte {
    74  	return NewWithTag(value, "xml").MustToXmlIndent(rootTag...)
    75  }
    76  
    77  func MustToXmlIndentString(value interface{}, rootTag ...string) string {
    78  	return NewWithTag(value, "xml").MustToXmlIndentString(rootTag...)
    79  }
    80  
    81  // ========================================================================
    82  // YAML
    83  // ========================================================================
    84  
    85  func VarToYaml(value interface{}) ([]byte, error) {
    86  	return NewWithTag(value, "yaml").ToYaml()
    87  }
    88  
    89  func VarToYamlString(value interface{}) (string, error) {
    90  	return NewWithTag(value, "yaml").ToYamlString()
    91  }
    92  
    93  func MustToYaml(value interface{}) []byte {
    94  	return NewWithTag(value, "yaml").MustToYaml()
    95  }
    96  
    97  func MustToYamlString(value interface{}) string {
    98  	return NewWithTag(value, "yaml").MustToYamlString()
    99  }
   100  
   101  // ========================================================================
   102  // TOML
   103  // ========================================================================
   104  
   105  func VarToToml(value interface{}) ([]byte, error) {
   106  	return NewWithTag(value, "toml").ToToml()
   107  }
   108  
   109  func VarToTomlString(value interface{}) (string, error) {
   110  	return NewWithTag(value, "toml").ToTomlString()
   111  }
   112  
   113  func MustToToml(value interface{}) []byte {
   114  	return NewWithTag(value, "toml").MustToToml()
   115  }
   116  
   117  func MustToTomlString(value interface{}) string {
   118  	return NewWithTag(value, "toml").MustToTomlString()
   119  }
   120  
   121  // ========================================================================
   122  // INI
   123  // ========================================================================
   124  
   125  func VarToIni(value interface{}) ([]byte, error) {
   126  	return NewWithTag(value, "ini").ToIni()
   127  }
   128  
   129  func VarToIniString(value interface{}) (string, error) {
   130  	return NewWithTag(value, "ini").ToIniString()
   131  }
   132  
   133  func MustToIni(value interface{}) []byte {
   134  	return NewWithTag(value, "ini").MustToIni()
   135  }
   136  
   137  func MustToIniString(value interface{}) string {
   138  	return NewWithTag(value, "ini").MustToIniString()
   139  }