From d5380974a0847cae0805650645fab7b266be8906 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 8 Aug 2016 16:16:12 -0700 Subject: [PATCH] vendor --- .../hashicorp/vault/helper/jsonutil/json.go | 48 +++++++++++++++++++ vendor/vendor.json | 6 +++ 2 files changed, 54 insertions(+) create mode 100644 vendor/github.com/hashicorp/vault/helper/jsonutil/json.go diff --git a/vendor/github.com/hashicorp/vault/helper/jsonutil/json.go b/vendor/github.com/hashicorp/vault/helper/jsonutil/json.go new file mode 100644 index 000000000..c237db0f6 --- /dev/null +++ b/vendor/github.com/hashicorp/vault/helper/jsonutil/json.go @@ -0,0 +1,48 @@ +package jsonutil + +import ( + "bytes" + "encoding/json" + "fmt" + "io" +) + +// Encodes/Marshals the given object into JSON +func EncodeJSON(in interface{}) ([]byte, error) { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + if err := enc.Encode(in); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// Decodes/Unmarshals the given JSON into a desired object +func DecodeJSON(data []byte, out interface{}) error { + if data == nil { + return fmt.Errorf("'data' being decoded is nil") + } + if out == nil { + return fmt.Errorf("output parameter 'out' is nil") + } + + return DecodeJSONFromReader(bytes.NewReader(data), out) +} + +// Decodes/Unmarshals the given io.Reader pointing to a JSON, into a desired object +func DecodeJSONFromReader(r io.Reader, out interface{}) error { + if r == nil { + return fmt.Errorf("'io.Reader' being decoded is nil") + } + if out == nil { + return fmt.Errorf("output parameter 'out' is nil") + } + + dec := json.NewDecoder(r) + + // While decoding JSON values, intepret the integer values as `json.Number`s instead of `float64`. + dec.UseNumber() + + // Since 'out' is an interface representing a pointer, pass it to the decoder without an '&' + return dec.Decode(out) +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 3be390290..c5e8c1bac 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -628,6 +628,12 @@ "revision": "bcf98fa8d61d1870c3af689f1b090b29a9c12d8c", "revisionTime": "2016-08-02T20:35:37Z" }, + { + "checksumSHA1": "5lR6EdY0ARRdKAq3hZcL38STD8Q=", + "path": "github.com/hashicorp/vault/helper/jsonutil", + "revision": "bcf98fa8d61d1870c3af689f1b090b29a9c12d8c", + "revisionTime": "2016-08-02T20:35:37Z" + }, { "checksumSHA1": "VMaF3Q7RIrRzvbnPbqxuSLryOvc=", "path": "github.com/hashicorp/yamux",