mirror of
https://gitee.com/johng/gf
synced 2026-07-02 19:31:07 +08:00
improve package gjson for automatic content type checking
This commit is contained in:
@ -207,16 +207,19 @@ func checkDataType(content []byte) string {
|
||||
return "json"
|
||||
} else if gregex.IsMatch(`^<.+>[\S\s]+<.+>$`, content) {
|
||||
return "xml"
|
||||
} else if gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*:\s*".+"`, content) ||
|
||||
gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*:\s*\w+`, content) {
|
||||
} else if gregex.IsMatch(`[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, content) ||
|
||||
gregex.IsMatch(`[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, content) {
|
||||
return "yml"
|
||||
} else if !gregex.IsMatch(`^[\s\t\n\r]*;.+`, content) &&
|
||||
!gregex.IsMatch(`[\s\t\n\r]+;.+`, content) &&
|
||||
(gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*".+"`, content) || gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*\w+`, content)) {
|
||||
return "toml"
|
||||
} else if gregex.IsMatch(`\[[\w]+\]`, content) &&
|
||||
gregex.IsMatch(`[\s\t\n\[\]]*[\w\-]+\s*=\s*.+`, content) &&
|
||||
!gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*=*\"*.+\"`, content) {
|
||||
!gregex.IsMatch(`^[\s\t\n\r]*#.+`, content) &&
|
||||
!gregex.IsMatch(`[\s\t\n\r]+#.+`, content) &&
|
||||
(gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*".+"`, content) || gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*\w+`, content)) {
|
||||
// Must contain "[xxx]" section.
|
||||
return "ini"
|
||||
} else if gregex.IsMatch(`[\s\t\n]*[\w\-\."]+\s*=\s*.+`, content) {
|
||||
return "toml"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -215,8 +215,7 @@ func Test_Load_Ini(t *testing.T) {
|
||||
|
||||
;注释
|
||||
|
||||
[addr]
|
||||
#注释
|
||||
[addr]
|
||||
ip = 127.0.0.1
|
||||
port=9001
|
||||
enable=true
|
||||
|
||||
Reference in New Issue
Block a user