enable adding raw JSON to an array (#145)
* enable adding JSON to an array * do not forget the comment
This commit is contained in:
parent
7592fcbe60
commit
5861452d64
6
array.go
6
array.go
|
@ -85,6 +85,12 @@ func (a *Array) Hex(val []byte) *Array {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawJSON adds already encoded JSON to the array.
|
||||||
|
func (a *Array) RawJSON(val []byte) *Array {
|
||||||
|
a.buf = appendJSON(enc.AppendArrayDelim(a.buf), val)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
// Err serializes and appends the err to the array.
|
// Err serializes and appends the err to the array.
|
||||||
func (a *Array) Err(err error) *Array {
|
func (a *Array) Err(err error) *Array {
|
||||||
marshaled := ErrorMarshalFunc(err)
|
marshaled := ErrorMarshalFunc(err)
|
||||||
|
|
|
@ -24,10 +24,11 @@ func TestArray(t *testing.T) {
|
||||||
Str("a").
|
Str("a").
|
||||||
Bytes([]byte("b")).
|
Bytes([]byte("b")).
|
||||||
Hex([]byte{0x1f}).
|
Hex([]byte{0x1f}).
|
||||||
|
RawJSON([]byte(`{"some":"json"}`)).
|
||||||
Time(time.Time{}).
|
Time(time.Time{}).
|
||||||
IPAddr(net.IP{192, 168, 0, 10}).
|
IPAddr(net.IP{192, 168, 0, 10}).
|
||||||
Dur(0)
|
Dur(0)
|
||||||
want := `[true,1,2,3,4,5,6,7,8,9,10,11.98122,12.987654321,"a","b","1f","0001-01-01T00:00:00Z","192.168.0.10",0]`
|
want := `[true,1,2,3,4,5,6,7,8,9,10,11.98122,12.987654321,"a","b","1f",{"some":"json"},"0001-01-01T00:00:00Z","192.168.0.10",0]`
|
||||||
if got := decodeObjectToStr(a.write([]byte{})); got != want {
|
if got := decodeObjectToStr(a.write([]byte{})); got != want {
|
||||||
t.Errorf("Array.write()\ngot: %s\nwant: %s", got, want)
|
t.Errorf("Array.write()\ngot: %s\nwant: %s", got, want)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue