mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
add function LoadContentType for package gjson
This commit is contained in:
parent
7cc1b239d4
commit
607821ecbc
@ -189,14 +189,22 @@ func LoadContent(data interface{}, safe ...bool) (*Json, error) {
|
||||
if len(content) == 0 {
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
return LoadContentType(checkDataType(content), content, safe...)
|
||||
}
|
||||
|
||||
// LoadContentType creates a Json object from given type and content,
|
||||
// supporting data content type as follows:
|
||||
// JSON, XML, INI, YAML and TOML.
|
||||
func LoadContentType(dataType string, data interface{}, safe ...bool) (*Json, error) {
|
||||
content := gconv.Bytes(data)
|
||||
if len(content) == 0 {
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
//ignore UTF8-BOM
|
||||
if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF {
|
||||
content = content[3:]
|
||||
}
|
||||
|
||||
return doLoadContent(checkDataType(content), content, safe...)
|
||||
|
||||
return doLoadContent(dataType, content, safe...)
|
||||
}
|
||||
|
||||
// checkDataType automatically checks and returns the data type for <content>.
|
||||
|
@ -113,8 +113,10 @@ func (c *Config) filePath(file ...string) (path string) {
|
||||
// The parameter <path> can be absolute or relative path,
|
||||
// but absolute path is strongly recommended.
|
||||
func (c *Config) SetPath(path string) error {
|
||||
isDir := false
|
||||
realPath := ""
|
||||
var (
|
||||
isDir = false
|
||||
realPath = ""
|
||||
)
|
||||
if file := gres.Get(path); file != nil {
|
||||
realPath = path
|
||||
isDir = file.FileInfo().IsDir()
|
||||
|
Loading…
Reference in New Issue
Block a user