mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Failed to return when Gini file grammar error
Failed to return when Gini file grammar error
This commit is contained in:
@ -16,7 +16,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Decode converts INI format to map.
|
||||
//Decode converts INI format to map
|
||||
func Decode(data []byte) (res map[string]interface{}, err error) {
|
||||
res = make(map[string]interface{})
|
||||
fieldMap := make(map[string]interface{})
|
||||
@ -72,10 +72,13 @@ func Decode(data []byte) (res map[string]interface{}, err error) {
|
||||
|
||||
}
|
||||
|
||||
if haveSection == false {
|
||||
return nil, fmt.Errorf("Failed to parse INI file, not found section")
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Encode converts map to INI format.
|
||||
//Encode converts map to INI format
|
||||
func Encode(data map[string]interface{}) (res []byte, err error) {
|
||||
w := new(bytes.Buffer)
|
||||
|
||||
@ -102,11 +105,12 @@ func Encode(data map[string]interface{}) (res []byte, err error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ToJson convert INI format to JSON.
|
||||
//ToJson convert INI format to JSON
|
||||
func ToJson(data []byte) (res []byte, err error) {
|
||||
iniMap, err := Decode(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.Marshal(iniMap)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user