Failed to return when Gini file grammar error

Failed to return when Gini file grammar error
This commit is contained in:
wenzi
2019-09-08 23:24:00 +08:00
committed by GitHub
parent 8bc1f457c7
commit 2eb0511ef5

View File

@ -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)
}