mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-06 15:46:00 +01:00
Reported in https://app.wercker.com/#buildstep/55cdc9467331453f08005062 Or just run `golint ./...` in the root of this repo Change-Id: I6870b220e101e264967fbb9495cd0bc65da70d78 Reviewed-on: https://review.gerrithub.io/243208 Reviewed-by: Kaushal M <kshlmster@gmail.com> Tested-by: Kaushal M <kshlmster@gmail.com>
35 lines
643 B
Go
35 lines
643 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func jsonFromBody(r io.Reader, v interface{}) error {
|
|
|
|
// Check body
|
|
body, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := json.Unmarshal(body, v); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetJSONFromRequest unmarshals JSON in `r` into `v`
|
|
func GetJSONFromRequest(r *http.Request, v interface{}) error {
|
|
defer r.Body.Close()
|
|
return jsonFromBody(r.Body, v)
|
|
}
|
|
|
|
// GetJSONFromResponse unmarshals JSON in `r` into `v`
|
|
func GetJSONFromResponse(r *http.Response, v interface{}) error {
|
|
defer r.Body.Close()
|
|
return jsonFromBody(r.Body, v)
|
|
}
|