Merge pull request #390 from abperiasamy/json-win
support DOS format config file on MS Windows OS
This commit is contained in:
@@ -23,6 +23,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"encoding/json"
|
||||
@@ -250,6 +252,9 @@ func (c store) Save(filename string) (err error) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
jsonStore = []byte(strings.Replace(string(jsonStore), "\n", "\r\n", -1))
|
||||
}
|
||||
_, err = file.Write(jsonStore)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -273,6 +278,10 @@ func (c *store) Load(filename string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
data = []byte(strings.Replace(string(data), "\r\n", "\n", -1))
|
||||
}
|
||||
|
||||
var loadedStore map[string]interface{}
|
||||
err = json.Unmarshal(data, &loadedStore)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user