Added common JSON encoding function.

This commit is contained in:
Adrian Gallagher
2015-03-25 18:30:15 +11:00
parent 2b25a5f98f
commit 11e3709221

View File

@@ -194,6 +194,16 @@ func SendHTTPGetRequest(url string, jsonDecode bool, result interface{}) (err er
return nil
}
func JSONEncode(v interface{}) ([]byte, error) {
json, err := json.Marshal(&v)
if err != nil {
return nil, err
}
return json, nil
}
func JSONDecode(data []byte, to interface{}) (error) {
err := json.Unmarshal(data, &to)