Failed to return when Gini file grammar error
Failed to return when Gini file grammar error
@@ -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)
}
