github.com/gogf/gf@v1.16.9/encoding/gparser/gparser_api_new_load.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  import (
    10  	"github.com/gogf/gf/encoding/gjson"
    11  )
    12  
    13  // New creates a Parser object with any variable type of <data>, but <data> should be a map, struct or
    14  // slice for data access reason, or it will make no sense.
    15  //
    16  // The parameter <safe> specifies whether using this Json object in concurrent-safe context, which
    17  // is false in default.
    18  func New(data interface{}, safe ...bool) *Parser {
    19  	return gjson.New(data, safe...)
    20  }
    21  
    22  // NewWithTag creates a Parser object with any variable type of <data>, but <data> should be a map
    23  // or slice for data access reason, or it will make no sense.
    24  //
    25  // The parameter <tags> specifies priority tags for struct conversion to map, multiple tags joined
    26  // with char ','.
    27  //
    28  // The parameter <safe> specifies whether using this Json object in concurrent-safe context, which
    29  // is false in default.
    30  func NewWithTag(data interface{}, tags string, safe ...bool) *Parser {
    31  	return gjson.NewWithTag(data, tags, safe...)
    32  }
    33  
    34  // Load loads content from specified file <path>,
    35  // and creates a Parser object from its content.
    36  func Load(path string, safe ...bool) (*Parser, error) {
    37  	return gjson.Load(path, safe...)
    38  }
    39  
    40  // LoadContent creates a Parser object from given content,
    41  // it checks the data type of <content> automatically,
    42  // supporting JSON, XML, INI, YAML and TOML types of data.
    43  func LoadContent(data interface{}, safe ...bool) (*Parser, error) {
    44  	return gjson.LoadContent(data, safe...)
    45  }
    46  
    47  func LoadJson(data interface{}, safe ...bool) (*Parser, error) {
    48  	return gjson.LoadJson(data, safe...)
    49  }
    50  
    51  func LoadXml(data interface{}, safe ...bool) (*Parser, error) {
    52  	return gjson.LoadXml(data, safe...)
    53  }
    54  
    55  func LoadYaml(data interface{}, safe ...bool) (*Parser, error) {
    56  	return gjson.LoadYaml(data, safe...)
    57  }
    58  
    59  func LoadToml(data interface{}, safe ...bool) (*Parser, error) {
    60  	return gjson.LoadToml(data, safe...)
    61  }
    62  
    63  func LoadIni(data interface{}, safe ...bool) (*Parser, error) {
    64  	return gjson.LoadIni(data, safe...)
    65  }