~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmstore.v5-unstable/internal/storetesting/json.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package storetesting // import "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting"
 
5
 
 
6
import (
 
7
        "bytes"
 
8
        "encoding/json"
 
9
        "io"
 
10
)
 
11
 
 
12
// MustMarshalJSON marshals the specified value using json.Marshal and
 
13
// returns the corresponding byte slice. If there is an error marshalling
 
14
// the value then MustMarshalJSON will panic.
 
15
func MustMarshalJSON(v interface{}) []byte {
 
16
        data, err := json.Marshal(v)
 
17
        if err != nil {
 
18
                panic(err)
 
19
        }
 
20
        return data
 
21
}
 
22
 
 
23
// JSONReader creates an io.Reader which can read the Marshalled value of v.
 
24
func JSONReader(v interface{}) io.Reader {
 
25
        return bytes.NewReader(MustMarshalJSON(v))
 
26
}