aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/davecgh
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/davecgh')
-rw-r--r--vendor/github.com/davecgh/go-spew/LICENSE15
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/bypass.go152
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/bypasssafe.go38
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/common.go341
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/config.go306
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/doc.go211
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/dump.go509
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/format.go419
-rw-r--r--vendor/github.com/davecgh/go-spew/spew/spew.go148
9 files changed, 2139 insertions, 0 deletions
diff --git a/vendor/github.com/davecgh/go-spew/LICENSE b/vendor/github.com/davecgh/go-spew/LICENSE
new file mode 100644
index 0000000..c836416
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/LICENSE
@@ -0,0 +1,15 @@
1ISC License
2
3Copyright (c) 2012-2016 Dave Collins <dave@davec.name>
4
5Permission to use, copy, modify, and distribute this software for any
6purpose with or without fee is hereby granted, provided that the above
7copyright notice and this permission notice appear in all copies.
8
9THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/vendor/github.com/davecgh/go-spew/spew/bypass.go b/vendor/github.com/davecgh/go-spew/spew/bypass.go
new file mode 100644
index 0000000..8a4a658
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/bypass.go
@@ -0,0 +1,152 @@
1// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
2//
3// Permission to use, copy, modify, and distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15// NOTE: Due to the following build constraints, this file will only be compiled
16// when the code is not running on Google App Engine, compiled by GopherJS, and
17// "-tags safe" is not added to the go build command line. The "disableunsafe"
18// tag is deprecated and thus should not be used.
19// +build !js,!appengine,!safe,!disableunsafe
20
21package spew
22
23import (
24 "reflect"
25 "unsafe"
26)
27
28const (
29 // UnsafeDisabled is a build-time constant which specifies whether or
30 // not access to the unsafe package is available.
31 UnsafeDisabled = false
32
33 // ptrSize is the size of a pointer on the current arch.
34 ptrSize = unsafe.Sizeof((*byte)(nil))
35)
36
37var (
38 // offsetPtr, offsetScalar, and offsetFlag are the offsets for the
39 // internal reflect.Value fields. These values are valid before golang
40 // commit ecccf07e7f9d which changed the format. The are also valid
41 // after commit 82f48826c6c7 which changed the format again to mirror
42 // the original format. Code in the init function updates these offsets
43 // as necessary.
44 offsetPtr = uintptr(ptrSize)
45 offsetScalar = uintptr(0)
46 offsetFlag = uintptr(ptrSize * 2)
47
48 // flagKindWidth and flagKindShift indicate various bits that the
49 // reflect package uses internally to track kind information.
50 //
51 // flagRO indicates whether or not the value field of a reflect.Value is
52 // read-only.
53 //
54 // flagIndir indicates whether the value field of a reflect.Value is
55 // the actual data or a pointer to the data.
56 //
57 // These values are valid before golang commit 90a7c3c86944 which
58 // changed their positions. Code in the init function updates these
59 // flags as necessary.
60 flagKindWidth = uintptr(5)
61 flagKindShift = uintptr(flagKindWidth - 1)
62 flagRO = uintptr(1 << 0)
63 flagIndir = uintptr(1 << 1)
64)
65
66func init() {
67 // Older versions of reflect.Value stored small integers directly in the
68 // ptr field (which is named val in the older versions). Versions
69 // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named
70 // scalar for this purpose which unfortunately came before the flag
71 // field, so the offset of the flag field is different for those
72 // versions.
73 //
74 // This code constructs a new reflect.Value from a known small integer
75 // and checks if the size of the reflect.Value struct indicates it has
76 // the scalar field. When it does, the offsets are updated accordingly.
77 vv := reflect.ValueOf(0xf00)
78 if unsafe.Sizeof(vv) == (ptrSize * 4) {
79 offsetScalar = ptrSize * 2
80 offsetFlag = ptrSize * 3
81 }
82
83 // Commit 90a7c3c86944 changed the flag positions such that the low
84 // order bits are the kind. This code extracts the kind from the flags
85 // field and ensures it's the correct type. When it's not, the flag
86 // order has been changed to the newer format, so the flags are updated
87 // accordingly.
88 upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag)
89 upfv := *(*uintptr)(upf)
90 flagKindMask := uintptr((1<<flagKindWidth - 1) << flagKindShift)
91 if (upfv&flagKindMask)>>flagKindShift != uintptr(reflect.Int) {
92 flagKindShift = 0
93 flagRO = 1 << 5
94 flagIndir = 1 << 6
95
96 // Commit adf9b30e5594 modified the flags to separate the
97 // flagRO flag into two bits which specifies whether or not the
98 // field is embedded. This causes flagIndir to move over a bit
99 // and means that flagRO is the combination of either of the
100 // original flagRO bit and the new bit.
101 //
102 // This code detects the change by extracting what used to be
103 // the indirect bit to ensure it's set. When it's not, the flag
104 // order has been changed to the newer format, so the flags are
105 // updated accordingly.
106 if upfv&flagIndir == 0 {
107 flagRO = 3 << 5
108 flagIndir = 1 << 7
109 }
110 }
111}
112
113// unsafeReflectValue converts the passed reflect.Value into a one that bypasses
114// the typical safety restrictions preventing access to unaddressable and
115// unexported data. It works by digging the raw pointer to the underlying
116// value out of the protected value and generating a new unprotected (unsafe)
117// reflect.Value to it.
118//
119// This allows us to check for implementations of the Stringer and error
120// interfaces to be used for pretty printing ordinarily unaddressable and
121// inaccessible values such as unexported struct fields.
122func unsafeReflectValue(v reflect.Value) (rv reflect.Value) {
123 indirects := 1
124 vt := v.Type()
125 upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr)
126 rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag))
127 if rvf&flagIndir != 0 {
128 vt = reflect.PtrTo(v.Type())
129 indirects++
130 } else if offsetScalar != 0 {
131 // The value is in the scalar field when it's not one of the
132 // reference types.
133 switch vt.Kind() {
134 case reflect.Uintptr:
135 case reflect.Chan:
136 case reflect.Func:
137 case reflect.Map:
138 case reflect.Ptr:
139 case reflect.UnsafePointer:
140 default:
141 upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) +
142 offsetScalar)
143 }
144 }
145
146 pv := reflect.NewAt(vt, upv)
147 rv = pv
148 for i := 0; i < indirects; i++ {
149 rv = rv.Elem()
150 }
151 return rv
152}
diff --git a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
new file mode 100644
index 0000000..1fe3cf3
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
@@ -0,0 +1,38 @@
1// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
2//
3// Permission to use, copy, modify, and distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15// NOTE: Due to the following build constraints, this file will only be compiled
16// when the code is running on Google App Engine, compiled by GopherJS, or
17// "-tags safe" is added to the go build command line. The "disableunsafe"
18// tag is deprecated and thus should not be used.
19// +build js appengine safe disableunsafe
20
21package spew
22
23import "reflect"
24
25const (
26 // UnsafeDisabled is a build-time constant which specifies whether or
27 // not access to the unsafe package is available.
28 UnsafeDisabled = true
29)
30
31// unsafeReflectValue typically converts the passed reflect.Value into a one
32// that bypasses the typical safety restrictions preventing access to
33// unaddressable and unexported data. However, doing this relies on access to
34// the unsafe package. This is a stub version which simply returns the passed
35// reflect.Value when the unsafe package is not available.
36func unsafeReflectValue(v reflect.Value) reflect.Value {
37 return v
38}
diff --git a/vendor/github.com/davecgh/go-spew/spew/common.go b/vendor/github.com/davecgh/go-spew/spew/common.go
new file mode 100644
index 0000000..7c519ff
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/common.go
@@ -0,0 +1,341 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17package spew
18
19import (
20 "bytes"
21 "fmt"
22 "io"
23 "reflect"
24 "sort"
25 "strconv"
26)
27
28// Some constants in the form of bytes to avoid string overhead. This mirrors
29// the technique used in the fmt package.
30var (
31 panicBytes = []byte("(PANIC=")
32 plusBytes = []byte("+")
33 iBytes = []byte("i")
34 trueBytes = []byte("true")
35 falseBytes = []byte("false")
36 interfaceBytes = []byte("(interface {})")
37 commaNewlineBytes = []byte(",\n")
38 newlineBytes = []byte("\n")
39 openBraceBytes = []byte("{")
40 openBraceNewlineBytes = []byte("{\n")
41 closeBraceBytes = []byte("}")
42 asteriskBytes = []byte("*")
43 colonBytes = []byte(":")
44 colonSpaceBytes = []byte(": ")
45 openParenBytes = []byte("(")
46 closeParenBytes = []byte(")")
47 spaceBytes = []byte(" ")
48 pointerChainBytes = []byte("->")
49 nilAngleBytes = []byte("<nil>")
50 maxNewlineBytes = []byte("<max depth reached>\n")
51 maxShortBytes = []byte("<max>")
52 circularBytes = []byte("<already shown>")
53 circularShortBytes = []byte("<shown>")
54 invalidAngleBytes = []byte("<invalid>")
55 openBracketBytes = []byte("[")
56 closeBracketBytes = []byte("]")
57 percentBytes = []byte("%")
58 precisionBytes = []byte(".")
59 openAngleBytes = []byte("<")
60 closeAngleBytes = []byte(">")
61 openMapBytes = []byte("map[")
62 closeMapBytes = []byte("]")
63 lenEqualsBytes = []byte("len=")
64 capEqualsBytes = []byte("cap=")
65)
66
67// hexDigits is used to map a decimal value to a hex digit.
68var hexDigits = "0123456789abcdef"
69
70// catchPanic handles any panics that might occur during the handleMethods
71// calls.
72func catchPanic(w io.Writer, v reflect.Value) {
73 if err := recover(); err != nil {
74 w.Write(panicBytes)
75 fmt.Fprintf(w, "%v", err)
76 w.Write(closeParenBytes)
77 }
78}
79
80// handleMethods attempts to call the Error and String methods on the underlying
81// type the passed reflect.Value represents and outputes the result to Writer w.
82//
83// It handles panics in any called methods by catching and displaying the error
84// as the formatted value.
85func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) {
86 // We need an interface to check if the type implements the error or
87 // Stringer interface. However, the reflect package won't give us an
88 // interface on certain things like unexported struct fields in order
89 // to enforce visibility rules. We use unsafe, when it's available,
90 // to bypass these restrictions since this package does not mutate the
91 // values.
92 if !v.CanInterface() {
93 if UnsafeDisabled {
94 return false
95 }
96
97 v = unsafeReflectValue(v)
98 }
99
100 // Choose whether or not to do error and Stringer interface lookups against
101 // the base type or a pointer to the base type depending on settings.
102 // Technically calling one of these methods with a pointer receiver can
103 // mutate the value, however, types which choose to satisify an error or
104 // Stringer interface with a pointer receiver should not be mutating their
105 // state inside these interface methods.
106 if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() {
107 v = unsafeReflectValue(v)
108 }
109 if v.CanAddr() {
110 v = v.Addr()
111 }
112
113 // Is it an error or Stringer?
114 switch iface := v.Interface().(type) {
115 case error:
116 defer catchPanic(w, v)
117 if cs.ContinueOnMethod {
118 w.Write(openParenBytes)
119 w.Write([]byte(iface.Error()))
120 w.Write(closeParenBytes)
121 w.Write(spaceBytes)
122 return false
123 }
124
125 w.Write([]byte(iface.Error()))
126 return true
127
128 case fmt.Stringer:
129 defer catchPanic(w, v)
130 if cs.ContinueOnMethod {
131 w.Write(openParenBytes)
132 w.Write([]byte(iface.String()))
133 w.Write(closeParenBytes)
134 w.Write(spaceBytes)
135 return false
136 }
137 w.Write([]byte(iface.String()))
138 return true
139 }
140 return false
141}
142
143// printBool outputs a boolean value as true or false to Writer w.
144func printBool(w io.Writer, val bool) {
145 if val {
146 w.Write(trueBytes)
147 } else {
148 w.Write(falseBytes)
149 }
150}
151
152// printInt outputs a signed integer value to Writer w.
153func printInt(w io.Writer, val int64, base int) {
154 w.Write([]byte(strconv.FormatInt(val, base)))
155}
156
157// printUint outputs an unsigned integer value to Writer w.
158func printUint(w io.Writer, val uint64, base int) {
159 w.Write([]byte(strconv.FormatUint(val, base)))
160}
161
162// printFloat outputs a floating point value using the specified precision,
163// which is expected to be 32 or 64bit, to Writer w.
164func printFloat(w io.Writer, val float64, precision int) {
165 w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision)))
166}
167
168// printComplex outputs a complex value using the specified float precision
169// for the real and imaginary parts to Writer w.
170func printComplex(w io.Writer, c complex128, floatPrecision int) {
171 r := real(c)
172 w.Write(openParenBytes)
173 w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision)))
174 i := imag(c)
175 if i >= 0 {
176 w.Write(plusBytes)
177 }
178 w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision)))
179 w.Write(iBytes)
180 w.Write(closeParenBytes)
181}
182
183// printHexPtr outputs a uintptr formatted as hexidecimal with a leading '0x'
184// prefix to Writer w.
185func printHexPtr(w io.Writer, p uintptr) {
186 // Null pointer.
187 num := uint64(p)
188 if num == 0 {
189 w.Write(nilAngleBytes)
190 return
191 }
192
193 // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix
194 buf := make([]byte, 18)
195
196 // It's simpler to construct the hex string right to left.
197 base := uint64(16)
198 i := len(buf) - 1
199 for num >= base {
200 buf[i] = hexDigits[num%base]
201 num /= base
202 i--
203 }
204 buf[i] = hexDigits[num]
205
206 // Add '0x' prefix.
207 i--
208 buf[i] = 'x'
209 i--
210 buf[i] = '0'
211
212 // Strip unused leading bytes.
213 buf = buf[i:]
214 w.Write(buf)
215}
216
217// valuesSorter implements sort.Interface to allow a slice of reflect.Value
218// elements to be sorted.
219type valuesSorter struct {
220 values []reflect.Value
221 strings []string // either nil or same len and values
222 cs *ConfigState
223}
224
225// newValuesSorter initializes a valuesSorter instance, which holds a set of
226// surrogate keys on which the data should be sorted. It uses flags in
227// ConfigState to decide if and how to populate those surrogate keys.
228func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface {
229 vs := &valuesSorter{values: values, cs: cs}
230 if canSortSimply(vs.values[0].Kind()) {
231 return vs
232 }
233 if !cs.DisableMethods {
234 vs.strings = make([]string, len(values))
235 for i := range vs.values {
236 b := bytes.Buffer{}
237 if !handleMethods(cs, &b, vs.values[i]) {
238 vs.strings = nil
239 break
240 }
241 vs.strings[i] = b.String()
242 }
243 }
244 if vs.strings == nil && cs.SpewKeys {
245 vs.strings = make([]string, len(values))
246 for i := range vs.values {
247 vs.strings[i] = Sprintf("%#v", vs.values[i].Interface())
248 }
249 }
250 return vs
251}
252
253// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted
254// directly, or whether it should be considered for sorting by surrogate keys
255// (if the ConfigState allows it).
256func canSortSimply(kind reflect.Kind) bool {
257 // This switch parallels valueSortLess, except for the default case.
258 switch kind {
259 case reflect.Bool:
260 return true
261 case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
262 return true
263 case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
264 return true
265 case reflect.Float32, reflect.Float64:
266 return true
267 case reflect.String:
268 return true
269 case reflect.Uintptr:
270 return true
271 case reflect.Array:
272 return true
273 }
274 return false
275}
276
277// Len returns the number of values in the slice. It is part of the
278// sort.Interface implementation.
279func (s *valuesSorter) Len() int {
280 return len(s.values)
281}
282
283// Swap swaps the values at the passed indices. It is part of the
284// sort.Interface implementation.
285func (s *valuesSorter) Swap(i, j int) {
286 s.values[i], s.values[j] = s.values[j], s.values[i]
287 if s.strings != nil {
288 s.strings[i], s.strings[j] = s.strings[j], s.strings[i]
289 }
290}
291
292// valueSortLess returns whether the first value should sort before the second
293// value. It is used by valueSorter.Less as part of the sort.Interface
294// implementation.
295func valueSortLess(a, b reflect.Value) bool {
296 switch a.Kind() {
297 case reflect.Bool:
298 return !a.Bool() && b.Bool()
299 case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
300 return a.Int() < b.Int()
301 case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
302 return a.Uint() < b.Uint()
303 case reflect.Float32, reflect.Float64:
304 return a.Float() < b.Float()
305 case reflect.String:
306 return a.String() < b.String()
307 case reflect.Uintptr:
308 return a.Uint() < b.Uint()
309 case reflect.Array:
310 // Compare the contents of both arrays.
311 l := a.Len()
312 for i := 0; i < l; i++ {
313 av := a.Index(i)
314 bv := b.Index(i)
315 if av.Interface() == bv.Interface() {
316 continue
317 }
318 return valueSortLess(av, bv)
319 }
320 }
321 return a.String() < b.String()
322}
323
324// Less returns whether the value at index i should sort before the
325// value at index j. It is part of the sort.Interface implementation.
326func (s *valuesSorter) Less(i, j int) bool {
327 if s.strings == nil {
328 return valueSortLess(s.values[i], s.values[j])
329 }
330 return s.strings[i] < s.strings[j]
331}
332
333// sortValues is a sort function that handles both native types and any type that
334// can be converted to error or Stringer. Other inputs are sorted according to
335// their Value.String() value to ensure display stability.
336func sortValues(values []reflect.Value, cs *ConfigState) {
337 if len(values) == 0 {
338 return
339 }
340 sort.Sort(newValuesSorter(values, cs))
341}
diff --git a/vendor/github.com/davecgh/go-spew/spew/config.go b/vendor/github.com/davecgh/go-spew/spew/config.go
new file mode 100644
index 0000000..2e3d22f
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/config.go
@@ -0,0 +1,306 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17package spew
18
19import (
20 "bytes"
21 "fmt"
22 "io"
23 "os"
24)
25
26// ConfigState houses the configuration options used by spew to format and
27// display values. There is a global instance, Config, that is used to control
28// all top-level Formatter and Dump functionality. Each ConfigState instance
29// provides methods equivalent to the top-level functions.
30//
31// The zero value for ConfigState provides no indentation. You would typically
32// want to set it to a space or a tab.
33//
34// Alternatively, you can use NewDefaultConfig to get a ConfigState instance
35// with default settings. See the documentation of NewDefaultConfig for default
36// values.
37type ConfigState struct {
38 // Indent specifies the string to use for each indentation level. The
39 // global config instance that all top-level functions use set this to a
40 // single space by default. If you would like more indentation, you might
41 // set this to a tab with "\t" or perhaps two spaces with " ".
42 Indent string
43
44 // MaxDepth controls the maximum number of levels to descend into nested
45 // data structures. The default, 0, means there is no limit.
46 //
47 // NOTE: Circular data structures are properly detected, so it is not
48 // necessary to set this value unless you specifically want to limit deeply
49 // nested data structures.
50 MaxDepth int
51
52 // DisableMethods specifies whether or not error and Stringer interfaces are
53 // invoked for types that implement them.
54 DisableMethods bool
55
56 // DisablePointerMethods specifies whether or not to check for and invoke
57 // error and Stringer interfaces on types which only accept a pointer
58 // receiver when the current type is not a pointer.
59 //
60 // NOTE: This might be an unsafe action since calling one of these methods
61 // with a pointer receiver could technically mutate the value, however,
62 // in practice, types which choose to satisify an error or Stringer
63 // interface with a pointer receiver should not be mutating their state
64 // inside these interface methods. As a result, this option relies on
65 // access to the unsafe package, so it will not have any effect when
66 // running in environments without access to the unsafe package such as
67 // Google App Engine or with the "safe" build tag specified.
68 DisablePointerMethods bool
69
70 // DisablePointerAddresses specifies whether to disable the printing of
71 // pointer addresses. This is useful when diffing data structures in tests.
72 DisablePointerAddresses bool
73
74 // DisableCapacities specifies whether to disable the printing of capacities
75 // for arrays, slices, maps and channels. This is useful when diffing
76 // data structures in tests.
77 DisableCapacities bool
78
79 // ContinueOnMethod specifies whether or not recursion should continue once
80 // a custom error or Stringer interface is invoked. The default, false,
81 // means it will print the results of invoking the custom error or Stringer
82 // interface and return immediately instead of continuing to recurse into
83 // the internals of the data type.
84 //
85 // NOTE: This flag does not have any effect if method invocation is disabled
86 // via the DisableMethods or DisablePointerMethods options.
87 ContinueOnMethod bool
88
89 // SortKeys specifies map keys should be sorted before being printed. Use
90 // this to have a more deterministic, diffable output. Note that only
91 // native types (bool, int, uint, floats, uintptr and string) and types
92 // that support the error or Stringer interfaces (if methods are
93 // enabled) are supported, with other types sorted according to the
94 // reflect.Value.String() output which guarantees display stability.
95 SortKeys bool
96
97 // SpewKeys specifies that, as a last resort attempt, map keys should
98 // be spewed to strings and sorted by those strings. This is only
99 // considered if SortKeys is true.
100 SpewKeys bool
101}
102
103// Config is the active configuration of the top-level functions.
104// The configuration can be changed by modifying the contents of spew.Config.
105var Config = ConfigState{Indent: " "}
106
107// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
108// passed with a Formatter interface returned by c.NewFormatter. It returns
109// the formatted string as a value that satisfies error. See NewFormatter
110// for formatting details.
111//
112// This function is shorthand for the following syntax:
113//
114// fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b))
115func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) {
116 return fmt.Errorf(format, c.convertArgs(a)...)
117}
118
119// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
120// passed with a Formatter interface returned by c.NewFormatter. It returns
121// the number of bytes written and any write error encountered. See
122// NewFormatter for formatting details.
123//
124// This function is shorthand for the following syntax:
125//
126// fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b))
127func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) {
128 return fmt.Fprint(w, c.convertArgs(a)...)
129}
130
131// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
132// passed with a Formatter interface returned by c.NewFormatter. It returns
133// the number of bytes written and any write error encountered. See
134// NewFormatter for formatting details.
135//
136// This function is shorthand for the following syntax:
137//
138// fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b))
139func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
140 return fmt.Fprintf(w, format, c.convertArgs(a)...)
141}
142
143// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
144// passed with a Formatter interface returned by c.NewFormatter. See
145// NewFormatter for formatting details.
146//
147// This function is shorthand for the following syntax:
148//
149// fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b))
150func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
151 return fmt.Fprintln(w, c.convertArgs(a)...)
152}
153
154// Print is a wrapper for fmt.Print that treats each argument as if it were
155// passed with a Formatter interface returned by c.NewFormatter. It returns
156// the number of bytes written and any write error encountered. See
157// NewFormatter for formatting details.
158//
159// This function is shorthand for the following syntax:
160//
161// fmt.Print(c.NewFormatter(a), c.NewFormatter(b))
162func (c *ConfigState) Print(a ...interface{}) (n int, err error) {
163 return fmt.Print(c.convertArgs(a)...)
164}
165
166// Printf is a wrapper for fmt.Printf that treats each argument as if it were
167// passed with a Formatter interface returned by c.NewFormatter. It returns
168// the number of bytes written and any write error encountered. See
169// NewFormatter for formatting details.
170//
171// This function is shorthand for the following syntax:
172//
173// fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b))
174func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) {
175 return fmt.Printf(format, c.convertArgs(a)...)
176}
177
178// Println is a wrapper for fmt.Println that treats each argument as if it were
179// passed with a Formatter interface returned by c.NewFormatter. It returns
180// the number of bytes written and any write error encountered. See
181// NewFormatter for formatting details.
182//
183// This function is shorthand for the following syntax:
184//
185// fmt.Println(c.NewFormatter(a), c.NewFormatter(b))
186func (c *ConfigState) Println(a ...interface{}) (n int, err error) {
187 return fmt.Println(c.convertArgs(a)...)
188}
189
190// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
191// passed with a Formatter interface returned by c.NewFormatter. It returns
192// the resulting string. See NewFormatter for formatting details.
193//
194// This function is shorthand for the following syntax:
195//
196// fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b))
197func (c *ConfigState) Sprint(a ...interface{}) string {
198 return fmt.Sprint(c.convertArgs(a)...)
199}
200
201// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
202// passed with a Formatter interface returned by c.NewFormatter. It returns
203// the resulting string. See NewFormatter for formatting details.
204//
205// This function is shorthand for the following syntax:
206//
207// fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b))
208func (c *ConfigState) Sprintf(format string, a ...interface{}) string {
209 return fmt.Sprintf(format, c.convertArgs(a)...)
210}
211
212// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
213// were passed with a Formatter interface returned by c.NewFormatter. It
214// returns the resulting string. See NewFormatter for formatting details.
215//
216// This function is shorthand for the following syntax:
217//
218// fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b))
219func (c *ConfigState) Sprintln(a ...interface{}) string {
220 return fmt.Sprintln(c.convertArgs(a)...)
221}
222
223/*
224NewFormatter returns a custom formatter that satisfies the fmt.Formatter
225interface. As a result, it integrates cleanly with standard fmt package
226printing functions. The formatter is useful for inline printing of smaller data
227types similar to the standard %v format specifier.
228
229The custom formatter only responds to the %v (most compact), %+v (adds pointer
230addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb
231combinations. Any other verbs such as %x and %q will be sent to the the
232standard fmt package for formatting. In addition, the custom formatter ignores
233the width and precision arguments (however they will still work on the format
234specifiers not handled by the custom formatter).
235
236Typically this function shouldn't be called directly. It is much easier to make
237use of the custom formatter by calling one of the convenience functions such as
238c.Printf, c.Println, or c.Printf.
239*/
240func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter {
241 return newFormatter(c, v)
242}
243
244// Fdump formats and displays the passed arguments to io.Writer w. It formats
245// exactly the same as Dump.
246func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) {
247 fdump(c, w, a...)
248}
249
250/*
251Dump displays the passed parameters to standard out with newlines, customizable
252indentation, and additional debug information such as complete types and all
253pointer addresses used to indirect to the final value. It provides the
254following features over the built-in printing facilities provided by the fmt
255package:
256
257 * Pointers are dereferenced and followed
258 * Circular data structures are detected and handled properly
259 * Custom Stringer/error interfaces are optionally invoked, including
260 on unexported types
261 * Custom types which only implement the Stringer/error interfaces via
262 a pointer receiver are optionally invoked when passing non-pointer
263 variables
264 * Byte arrays and slices are dumped like the hexdump -C command which
265 includes offsets, byte values in hex, and ASCII output
266
267The configuration options are controlled by modifying the public members
268of c. See ConfigState for options documentation.
269
270See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to
271get the formatted result as a string.
272*/
273func (c *ConfigState) Dump(a ...interface{}) {
274 fdump(c, os.Stdout, a...)
275}
276
277// Sdump returns a string with the passed arguments formatted exactly the same
278// as Dump.
279func (c *ConfigState) Sdump(a ...interface{}) string {
280 var buf bytes.Buffer
281 fdump(c, &buf, a...)
282 return buf.String()
283}
284
285// convertArgs accepts a slice of arguments and returns a slice of the same
286// length with each argument converted to a spew Formatter interface using
287// the ConfigState associated with s.
288func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) {
289 formatters = make([]interface{}, len(args))
290 for index, arg := range args {
291 formatters[index] = newFormatter(c, arg)
292 }
293 return formatters
294}
295
296// NewDefaultConfig returns a ConfigState with the following default settings.
297//
298// Indent: " "
299// MaxDepth: 0
300// DisableMethods: false
301// DisablePointerMethods: false
302// ContinueOnMethod: false
303// SortKeys: false
304func NewDefaultConfig() *ConfigState {
305 return &ConfigState{Indent: " "}
306}
diff --git a/vendor/github.com/davecgh/go-spew/spew/doc.go b/vendor/github.com/davecgh/go-spew/spew/doc.go
new file mode 100644
index 0000000..aacaac6
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/doc.go
@@ -0,0 +1,211 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/*
18Package spew implements a deep pretty printer for Go data structures to aid in
19debugging.
20
21A quick overview of the additional features spew provides over the built-in
22printing facilities for Go data types are as follows:
23
24 * Pointers are dereferenced and followed
25 * Circular data structures are detected and handled properly
26 * Custom Stringer/error interfaces are optionally invoked, including
27 on unexported types
28 * Custom types which only implement the Stringer/error interfaces via
29 a pointer receiver are optionally invoked when passing non-pointer
30 variables
31 * Byte arrays and slices are dumped like the hexdump -C command which
32 includes offsets, byte values in hex, and ASCII output (only when using
33 Dump style)
34
35There are two different approaches spew allows for dumping Go data structures:
36
37 * Dump style which prints with newlines, customizable indentation,
38 and additional debug information such as types and all pointer addresses
39 used to indirect to the final value
40 * A custom Formatter interface that integrates cleanly with the standard fmt
41 package and replaces %v, %+v, %#v, and %#+v to provide inline printing
42 similar to the default %v while providing the additional functionality
43 outlined above and passing unsupported format verbs such as %x and %q
44 along to fmt
45
46Quick Start
47
48This section demonstrates how to quickly get started with spew. See the
49sections below for further details on formatting and configuration options.
50
51To dump a variable with full newlines, indentation, type, and pointer
52information use Dump, Fdump, or Sdump:
53 spew.Dump(myVar1, myVar2, ...)
54 spew.Fdump(someWriter, myVar1, myVar2, ...)
55 str := spew.Sdump(myVar1, myVar2, ...)
56
57Alternatively, if you would prefer to use format strings with a compacted inline
58printing style, use the convenience wrappers Printf, Fprintf, etc with
59%v (most compact), %+v (adds pointer addresses), %#v (adds types), or
60%#+v (adds types and pointer addresses):
61 spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
62 spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
63 spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
64 spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
65
66Configuration Options
67
68Configuration of spew is handled by fields in the ConfigState type. For
69convenience, all of the top-level functions use a global state available
70via the spew.Config global.
71
72It is also possible to create a ConfigState instance that provides methods
73equivalent to the top-level functions. This allows concurrent configuration
74options. See the ConfigState documentation for more details.
75
76The following configuration options are available:
77 * Indent
78 String to use for each indentation level for Dump functions.
79 It is a single space by default. A popular alternative is "\t".
80
81 * MaxDepth
82 Maximum number of levels to descend into nested data structures.
83 There is no limit by default.
84
85 * DisableMethods
86 Disables invocation of error and Stringer interface methods.
87 Method invocation is enabled by default.
88
89 * DisablePointerMethods
90 Disables invocation of error and Stringer interface methods on types
91 which only accept pointer receivers from non-pointer variables.
92 Pointer method invocation is enabled by default.
93
94 * DisablePointerAddresses
95 DisablePointerAddresses specifies whether to disable the printing of
96 pointer addresses. This is useful when diffing data structures in tests.
97
98 * DisableCapacities
99 DisableCapacities specifies whether to disable the printing of
100 capacities for arrays, slices, maps and channels. This is useful when
101 diffing data structures in tests.
102
103 * ContinueOnMethod
104 Enables recursion into types after invoking error and Stringer interface
105 methods. Recursion after method invocation is disabled by default.
106
107 * SortKeys
108 Specifies map keys should be sorted before being printed. Use
109 this to have a more deterministic, diffable output. Note that
110 only native types (bool, int, uint, floats, uintptr and string)
111 and types which implement error or Stringer interfaces are
112 supported with other types sorted according to the
113 reflect.Value.String() output which guarantees display
114 stability. Natural map order is used by default.
115
116 * SpewKeys
117 Specifies that, as a last resort attempt, map keys should be
118 spewed to strings and sorted by those strings. This is only
119 considered if SortKeys is true.
120
121Dump Usage
122
123Simply call spew.Dump with a list of variables you want to dump:
124
125 spew.Dump(myVar1, myVar2, ...)
126
127You may also call spew.Fdump if you would prefer to output to an arbitrary
128io.Writer. For example, to dump to standard error:
129
130 spew.Fdump(os.Stderr, myVar1, myVar2, ...)
131
132A third option is to call spew.Sdump to get the formatted output as a string:
133
134 str := spew.Sdump(myVar1, myVar2, ...)
135
136Sample Dump Output
137
138See the Dump example for details on the setup of the types and variables being
139shown here.
140
141 (main.Foo) {
142 unexportedField: (*main.Bar)(0xf84002e210)({
143 flag: (main.Flag) flagTwo,
144 data: (uintptr) <nil>
145 }),
146 ExportedField: (map[interface {}]interface {}) (len=1) {
147 (string) (len=3) "one": (bool) true
148 }
149 }
150
151Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C
152command as shown.
153 ([]uint8) (len=32 cap=32) {
154 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
155 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0|
156 00000020 31 32 |12|
157 }
158
159Custom Formatter
160
161Spew provides a custom formatter that implements the fmt.Formatter interface
162so that it integrates cleanly with standard fmt package printing functions. The
163formatter is useful for inline printing of smaller data types similar to the
164standard %v format specifier.
165
166The custom formatter only responds to the %v (most compact), %+v (adds pointer
167addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb
168combinations. Any other verbs such as %x and %q will be sent to the the
169standard fmt package for formatting. In addition, the custom formatter ignores
170the width and precision arguments (however they will still work on the format
171specifiers not handled by the custom formatter).
172
173Custom Formatter Usage
174
175The simplest way to make use of the spew custom formatter is to call one of the
176convenience functions such as spew.Printf, spew.Println, or spew.Printf. The
177functions have syntax you are most likely already familiar with:
178
179 spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
180 spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
181 spew.Println(myVar, myVar2)
182 spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
183 spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
184
185See the Index for the full list convenience functions.
186
187Sample Formatter Output
188
189Double pointer to a uint8:
190 %v: <**>5
191 %+v: <**>(0xf8400420d0->0xf8400420c8)5
192 %#v: (**uint8)5
193 %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5
194
195Pointer to circular struct with a uint8 field and a pointer to itself:
196 %v: <*>{1 <*><shown>}
197 %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)<shown>}
198 %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)<shown>}
199 %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)<shown>}
200
201See the Printf example for details on the setup of variables being shown
202here.
203
204Errors
205
206Since it is possible for custom Stringer/error interfaces to panic, spew
207detects them and handles them internally by printing the panic information
208inline with the output. Since spew is intended to provide deep pretty printing
209capabilities on structures, it intentionally does not return any errors.
210*/
211package spew
diff --git a/vendor/github.com/davecgh/go-spew/spew/dump.go b/vendor/github.com/davecgh/go-spew/spew/dump.go
new file mode 100644
index 0000000..df1d582
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/dump.go
@@ -0,0 +1,509 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17package spew
18
19import (
20 "bytes"
21 "encoding/hex"
22 "fmt"
23 "io"
24 "os"
25 "reflect"
26 "regexp"
27 "strconv"
28 "strings"
29)
30
31var (
32 // uint8Type is a reflect.Type representing a uint8. It is used to
33 // convert cgo types to uint8 slices for hexdumping.
34 uint8Type = reflect.TypeOf(uint8(0))
35
36 // cCharRE is a regular expression that matches a cgo char.
37 // It is used to detect character arrays to hexdump them.
38 cCharRE = regexp.MustCompile("^.*\\._Ctype_char$")
39
40 // cUnsignedCharRE is a regular expression that matches a cgo unsigned
41 // char. It is used to detect unsigned character arrays to hexdump
42 // them.
43 cUnsignedCharRE = regexp.MustCompile("^.*\\._Ctype_unsignedchar$")
44
45 // cUint8tCharRE is a regular expression that matches a cgo uint8_t.
46 // It is used to detect uint8_t arrays to hexdump them.
47 cUint8tCharRE = regexp.MustCompile("^.*\\._Ctype_uint8_t$")
48)
49
50// dumpState contains information about the state of a dump operation.
51type dumpState struct {
52 w io.Writer
53 depth int
54 pointers map[uintptr]int
55 ignoreNextType bool
56 ignoreNextIndent bool
57 cs *ConfigState
58}
59
60// indent performs indentation according to the depth level and cs.Indent
61// option.
62func (d *dumpState) indent() {
63 if d.ignoreNextIndent {
64 d.ignoreNextIndent = false
65 return
66 }
67 d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth))
68}
69
70// unpackValue returns values inside of non-nil interfaces when possible.
71// This is useful for data types like structs, arrays, slices, and maps which
72// can contain varying types packed inside an interface.
73func (d *dumpState) unpackValue(v reflect.Value) reflect.Value {
74 if v.Kind() == reflect.Interface && !v.IsNil() {
75 v = v.Elem()
76 }
77 return v
78}
79
80// dumpPtr handles formatting of pointers by indirecting them as necessary.
81func (d *dumpState) dumpPtr(v reflect.Value) {
82 // Remove pointers at or below the current depth from map used to detect
83 // circular refs.
84 for k, depth := range d.pointers {
85 if depth >= d.depth {
86 delete(d.pointers, k)
87 }
88 }
89
90 // Keep list of all dereferenced pointers to show later.
91 pointerChain := make([]uintptr, 0)
92
93 // Figure out how many levels of indirection there are by dereferencing
94 // pointers and unpacking interfaces down the chain while detecting circular
95 // references.
96 nilFound := false
97 cycleFound := false
98 indirects := 0
99 ve := v
100 for ve.Kind() == reflect.Ptr {
101 if ve.IsNil() {
102 nilFound = true
103 break
104 }
105 indirects++
106 addr := ve.Pointer()
107 pointerChain = append(pointerChain, addr)
108 if pd, ok := d.pointers[addr]; ok && pd < d.depth {
109 cycleFound = true
110 indirects--
111 break
112 }
113 d.pointers[addr] = d.depth
114
115 ve = ve.Elem()
116 if ve.Kind() == reflect.Interface {
117 if ve.IsNil() {
118 nilFound = true
119 break
120 }
121 ve = ve.Elem()
122 }
123 }
124
125 // Display type information.
126 d.w.Write(openParenBytes)
127 d.w.Write(bytes.Repeat(asteriskBytes, indirects))
128 d.w.Write([]byte(ve.Type().String()))
129 d.w.Write(closeParenBytes)
130
131 // Display pointer information.
132 if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 {
133 d.w.Write(openParenBytes)
134 for i, addr := range pointerChain {
135 if i > 0 {
136 d.w.Write(pointerChainBytes)
137 }
138 printHexPtr(d.w, addr)
139 }
140 d.w.Write(closeParenBytes)
141 }
142
143 // Display dereferenced value.
144 d.w.Write(openParenBytes)
145 switch {
146 case nilFound == true:
147 d.w.Write(nilAngleBytes)
148
149 case cycleFound == true:
150 d.w.Write(circularBytes)
151
152 default:
153 d.ignoreNextType = true
154 d.dump(ve)
155 }
156 d.w.Write(closeParenBytes)
157}
158
159// dumpSlice handles formatting of arrays and slices. Byte (uint8 under
160// reflection) arrays and slices are dumped in hexdump -C fashion.
161func (d *dumpState) dumpSlice(v reflect.Value) {
162 // Determine whether this type should be hex dumped or not. Also,
163 // for types which should be hexdumped, try to use the underlying data
164 // first, then fall back to trying to convert them to a uint8 slice.
165 var buf []uint8
166 doConvert := false
167 doHexDump := false
168 numEntries := v.Len()
169 if numEntries > 0 {
170 vt := v.Index(0).Type()
171 vts := vt.String()
172 switch {
173 // C types that need to be converted.
174 case cCharRE.MatchString(vts):
175 fallthrough
176 case cUnsignedCharRE.MatchString(vts):
177 fallthrough
178 case cUint8tCharRE.MatchString(vts):
179 doConvert = true
180
181 // Try to use existing uint8 slices and fall back to converting
182 // and copying if that fails.
183 case vt.Kind() == reflect.Uint8:
184 // We need an addressable interface to convert the type
185 // to a byte slice. However, the reflect package won't
186 // give us an interface on certain things like
187 // unexported struct fields in order to enforce
188 // visibility rules. We use unsafe, when available, to
189 // bypass these restrictions since this package does not
190 // mutate the values.
191 vs := v
192 if !vs.CanInterface() || !vs.CanAddr() {
193 vs = unsafeReflectValue(vs)
194 }
195 if !UnsafeDisabled {
196 vs = vs.Slice(0, numEntries)
197
198 // Use the existing uint8 slice if it can be
199 // type asserted.
200 iface := vs.Interface()
201 if slice, ok := iface.([]uint8); ok {
202 buf = slice
203 doHexDump = true
204 break
205 }
206 }
207
208 // The underlying data needs to be converted if it can't
209 // be type asserted to a uint8 slice.
210 doConvert = true
211 }
212
213 // Copy and convert the underlying type if needed.
214 if doConvert && vt.ConvertibleTo(uint8Type) {
215 // Convert and copy each element into a uint8 byte
216 // slice.
217 buf = make([]uint8, numEntries)
218 for i := 0; i < numEntries; i++ {
219 vv := v.Index(i)
220 buf[i] = uint8(vv.Convert(uint8Type).Uint())
221 }
222 doHexDump = true
223 }
224 }
225
226 // Hexdump the entire slice as needed.
227 if doHexDump {
228 indent := strings.Repeat(d.cs.Indent, d.depth)
229 str := indent + hex.Dump(buf)
230 str = strings.Replace(str, "\n", "\n"+indent, -1)
231 str = strings.TrimRight(str, d.cs.Indent)
232 d.w.Write([]byte(str))
233 return
234 }
235
236 // Recursively call dump for each item.
237 for i := 0; i < numEntries; i++ {
238 d.dump(d.unpackValue(v.Index(i)))
239 if i < (numEntries - 1) {
240 d.w.Write(commaNewlineBytes)
241 } else {
242 d.w.Write(newlineBytes)
243 }
244 }
245}
246
247// dump is the main workhorse for dumping a value. It uses the passed reflect
248// value to figure out what kind of object we are dealing with and formats it
249// appropriately. It is a recursive function, however circular data structures
250// are detected and handled properly.
251func (d *dumpState) dump(v reflect.Value) {
252 // Handle invalid reflect values immediately.
253 kind := v.Kind()
254 if kind == reflect.Invalid {
255 d.w.Write(invalidAngleBytes)
256 return
257 }
258
259 // Handle pointers specially.
260 if kind == reflect.Ptr {
261 d.indent()
262 d.dumpPtr(v)
263 return
264 }
265
266 // Print type information unless already handled elsewhere.
267 if !d.ignoreNextType {
268 d.indent()
269 d.w.Write(openParenBytes)
270 d.w.Write([]byte(v.Type().String()))
271 d.w.Write(closeParenBytes)
272 d.w.Write(spaceBytes)
273 }
274 d.ignoreNextType = false
275
276 // Display length and capacity if the built-in len and cap functions
277 // work with the value's kind and the len/cap itself is non-zero.
278 valueLen, valueCap := 0, 0
279 switch v.Kind() {
280 case reflect.Array, reflect.Slice, reflect.Chan:
281 valueLen, valueCap = v.Len(), v.Cap()
282 case reflect.Map, reflect.String:
283 valueLen = v.Len()
284 }
285 if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 {
286 d.w.Write(openParenBytes)
287 if valueLen != 0 {
288 d.w.Write(lenEqualsBytes)
289 printInt(d.w, int64(valueLen), 10)
290 }
291 if !d.cs.DisableCapacities && valueCap != 0 {
292 if valueLen != 0 {
293 d.w.Write(spaceBytes)
294 }
295 d.w.Write(capEqualsBytes)
296 printInt(d.w, int64(valueCap), 10)
297 }
298 d.w.Write(closeParenBytes)
299 d.w.Write(spaceBytes)
300 }
301
302 // Call Stringer/error interfaces if they exist and the handle methods flag
303 // is enabled
304 if !d.cs.DisableMethods {
305 if (kind != reflect.Invalid) && (kind != reflect.Interface) {
306 if handled := handleMethods(d.cs, d.w, v); handled {
307 return
308 }
309 }
310 }
311
312 switch kind {
313 case reflect.Invalid:
314 // Do nothing. We should never get here since invalid has already
315 // been handled above.
316
317 case reflect.Bool:
318 printBool(d.w, v.Bool())
319
320 case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
321 printInt(d.w, v.Int(), 10)
322
323 case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
324 printUint(d.w, v.Uint(), 10)
325
326 case reflect.Float32:
327 printFloat(d.w, v.Float(), 32)
328
329 case reflect.Float64:
330 printFloat(d.w, v.Float(), 64)
331
332 case reflect.Complex64:
333 printComplex(d.w, v.Complex(), 32)
334
335 case reflect.Complex128:
336 printComplex(d.w, v.Complex(), 64)
337
338 case reflect.Slice:
339 if v.IsNil() {
340 d.w.Write(nilAngleBytes)
341 break
342 }
343 fallthrough
344
345 case reflect.Array:
346 d.w.Write(openBraceNewlineBytes)
347 d.depth++
348 if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
349 d.indent()
350 d.w.Write(maxNewlineBytes)
351 } else {
352 d.dumpSlice(v)
353 }
354 d.depth--
355 d.indent()
356 d.w.Write(closeBraceBytes)
357
358 case reflect.String:
359 d.w.Write([]byte(strconv.Quote(v.String())))
360
361 case reflect.Interface:
362 // The only time we should get here is for nil interfaces due to
363 // unpackValue calls.
364 if v.IsNil() {
365 d.w.Write(nilAngleBytes)
366 }
367
368 case reflect.Ptr:
369 // Do nothing. We should never get here since pointers have already
370 // been handled above.
371
372 case reflect.Map:
373 // nil maps should be indicated as different than empty maps
374 if v.IsNil() {
375 d.w.Write(nilAngleBytes)
376 break
377 }
378
379 d.w.Write(openBraceNewlineBytes)
380 d.depth++
381 if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
382 d.indent()
383 d.w.Write(maxNewlineBytes)
384 } else {
385 numEntries := v.Len()
386 keys := v.MapKeys()
387 if d.cs.SortKeys {
388 sortValues(keys, d.cs)
389 }
390 for i, key := range keys {
391 d.dump(d.unpackValue(key))
392 d.w.Write(colonSpaceBytes)
393 d.ignoreNextIndent = true
394 d.dump(d.unpackValue(v.MapIndex(key)))
395 if i < (numEntries - 1) {
396 d.w.Write(commaNewlineBytes)
397 } else {
398 d.w.Write(newlineBytes)
399 }
400 }
401 }
402 d.depth--
403 d.indent()
404 d.w.Write(closeBraceBytes)
405
406 case reflect.Struct:
407 d.w.Write(openBraceNewlineBytes)
408 d.depth++
409 if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
410 d.indent()
411 d.w.Write(maxNewlineBytes)
412 } else {
413 vt := v.Type()
414 numFields := v.NumField()
415 for i := 0; i < numFields; i++ {
416 d.indent()
417 vtf := vt.Field(i)
418 d.w.Write([]byte(vtf.Name))
419 d.w.Write(colonSpaceBytes)
420 d.ignoreNextIndent = true
421 d.dump(d.unpackValue(v.Field(i)))
422 if i < (numFields - 1) {
423 d.w.Write(commaNewlineBytes)
424 } else {
425 d.w.Write(newlineBytes)
426 }
427 }
428 }
429 d.depth--
430 d.indent()
431 d.w.Write(closeBraceBytes)
432
433 case reflect.Uintptr:
434 printHexPtr(d.w, uintptr(v.Uint()))
435
436 case reflect.UnsafePointer, reflect.Chan, reflect.Func:
437 printHexPtr(d.w, v.Pointer())
438
439 // There were not any other types at the time this code was written, but
440 // fall back to letting the default fmt package handle it in case any new
441 // types are added.
442 default:
443 if v.CanInterface() {
444 fmt.Fprintf(d.w, "%v", v.Interface())
445 } else {
446 fmt.Fprintf(d.w, "%v", v.String())
447 }
448 }
449}
450
451// fdump is a helper function to consolidate the logic from the various public
452// methods which take varying writers and config states.
453func fdump(cs *ConfigState, w io.Writer, a ...interface{}) {
454 for _, arg := range a {
455 if arg == nil {
456 w.Write(interfaceBytes)
457 w.Write(spaceBytes)
458 w.Write(nilAngleBytes)
459 w.Write(newlineBytes)
460 continue
461 }
462
463 d := dumpState{w: w, cs: cs}
464 d.pointers = make(map[uintptr]int)
465 d.dump(reflect.ValueOf(arg))
466 d.w.Write(newlineBytes)
467 }
468}
469
470// Fdump formats and displays the passed arguments to io.Writer w. It formats
471// exactly the same as Dump.
472func Fdump(w io.Writer, a ...interface{}) {
473 fdump(&Config, w, a...)
474}
475
476// Sdump returns a string with the passed arguments formatted exactly the same
477// as Dump.
478func Sdump(a ...interface{}) string {
479 var buf bytes.Buffer
480 fdump(&Config, &buf, a...)
481 return buf.String()
482}
483
484/*
485Dump displays the passed parameters to standard out with newlines, customizable
486indentation, and additional debug information such as complete types and all
487pointer addresses used to indirect to the final value. It provides the
488following features over the built-in printing facilities provided by the fmt
489package:
490
491 * Pointers are dereferenced and followed
492 * Circular data structures are detected and handled properly
493 * Custom Stringer/error interfaces are optionally invoked, including
494 on unexported types
495 * Custom types which only implement the Stringer/error interfaces via
496 a pointer receiver are optionally invoked when passing non-pointer
497 variables
498 * Byte arrays and slices are dumped like the hexdump -C command which
499 includes offsets, byte values in hex, and ASCII output
500
501The configuration options are controlled by an exported package global,
502spew.Config. See ConfigState for options documentation.
503
504See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to
505get the formatted result as a string.
506*/
507func Dump(a ...interface{}) {
508 fdump(&Config, os.Stdout, a...)
509}
diff --git a/vendor/github.com/davecgh/go-spew/spew/format.go b/vendor/github.com/davecgh/go-spew/spew/format.go
new file mode 100644
index 0000000..c49875b
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/format.go
@@ -0,0 +1,419 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17package spew
18
19import (
20 "bytes"
21 "fmt"
22 "reflect"
23 "strconv"
24 "strings"
25)
26
27// supportedFlags is a list of all the character flags supported by fmt package.
28const supportedFlags = "0-+# "
29
30// formatState implements the fmt.Formatter interface and contains information
31// about the state of a formatting operation. The NewFormatter function can
32// be used to get a new Formatter which can be used directly as arguments
33// in standard fmt package printing calls.
34type formatState struct {
35 value interface{}
36 fs fmt.State
37 depth int
38 pointers map[uintptr]int
39 ignoreNextType bool
40 cs *ConfigState
41}
42
43// buildDefaultFormat recreates the original format string without precision
44// and width information to pass in to fmt.Sprintf in the case of an
45// unrecognized type. Unless new types are added to the language, this
46// function won't ever be called.
47func (f *formatState) buildDefaultFormat() (format string) {
48 buf := bytes.NewBuffer(percentBytes)
49
50 for _, flag := range supportedFlags {
51 if f.fs.Flag(int(flag)) {
52 buf.WriteRune(flag)
53 }
54 }
55
56 buf.WriteRune('v')
57
58 format = buf.String()
59 return format
60}
61
62// constructOrigFormat recreates the original format string including precision
63// and width information to pass along to the standard fmt package. This allows
64// automatic deferral of all format strings this package doesn't support.
65func (f *formatState) constructOrigFormat(verb rune) (format string) {
66 buf := bytes.NewBuffer(percentBytes)
67
68 for _, flag := range supportedFlags {
69 if f.fs.Flag(int(flag)) {
70 buf.WriteRune(flag)
71 }
72 }
73
74 if width, ok := f.fs.Width(); ok {
75 buf.WriteString(strconv.Itoa(width))
76 }
77
78 if precision, ok := f.fs.Precision(); ok {
79 buf.Write(precisionBytes)
80 buf.WriteString(strconv.Itoa(precision))
81 }
82
83 buf.WriteRune(verb)
84
85 format = buf.String()
86 return format
87}
88
89// unpackValue returns values inside of non-nil interfaces when possible and
90// ensures that types for values which have been unpacked from an interface
91// are displayed when the show types flag is also set.
92// This is useful for data types like structs, arrays, slices, and maps which
93// can contain varying types packed inside an interface.
94func (f *formatState) unpackValue(v reflect.Value) reflect.Value {
95 if v.Kind() == reflect.Interface {
96 f.ignoreNextType = false
97 if !v.IsNil() {
98 v = v.Elem()
99 }
100 }
101 return v
102}
103
104// formatPtr handles formatting of pointers by indirecting them as necessary.
105func (f *formatState) formatPtr(v reflect.Value) {
106 // Display nil if top level pointer is nil.
107 showTypes := f.fs.Flag('#')
108 if v.IsNil() && (!showTypes || f.ignoreNextType) {
109 f.fs.Write(nilAngleBytes)
110 return
111 }
112
113 // Remove pointers at or below the current depth from map used to detect
114 // circular refs.
115 for k, depth := range f.pointers {
116 if depth >= f.depth {
117 delete(f.pointers, k)
118 }
119 }
120
121 // Keep list of all dereferenced pointers to possibly show later.
122 pointerChain := make([]uintptr, 0)
123
124 // Figure out how many levels of indirection there are by derferencing
125 // pointers and unpacking interfaces down the chain while detecting circular
126 // references.
127 nilFound := false
128 cycleFound := false
129 indirects := 0
130 ve := v
131 for ve.Kind() == reflect.Ptr {
132 if ve.IsNil() {
133 nilFound = true
134 break
135 }
136 indirects++
137 addr := ve.Pointer()
138 pointerChain = append(pointerChain, addr)
139 if pd, ok := f.pointers[addr]; ok && pd < f.depth {
140 cycleFound = true
141 indirects--
142 break
143 }
144 f.pointers[addr] = f.depth
145
146 ve = ve.Elem()
147 if ve.Kind() == reflect.Interface {
148 if ve.IsNil() {
149 nilFound = true
150 break
151 }
152 ve = ve.Elem()
153 }
154 }
155
156 // Display type or indirection level depending on flags.
157 if showTypes && !f.ignoreNextType {
158 f.fs.Write(openParenBytes)
159 f.fs.Write(bytes.Repeat(asteriskBytes, indirects))
160 f.fs.Write([]byte(ve.Type().String()))
161 f.fs.Write(closeParenBytes)
162 } else {
163 if nilFound || cycleFound {
164 indirects += strings.Count(ve.Type().String(), "*")
165 }
166 f.fs.Write(openAngleBytes)
167 f.fs.Write([]byte(strings.Repeat("*", indirects)))
168 f.fs.Write(closeAngleBytes)
169 }
170
171 // Display pointer information depending on flags.
172 if f.fs.Flag('+') && (len(pointerChain) > 0) {
173 f.fs.Write(openParenBytes)
174 for i, addr := range pointerChain {
175 if i > 0 {
176 f.fs.Write(pointerChainBytes)
177 }
178 printHexPtr(f.fs, addr)
179 }
180 f.fs.Write(closeParenBytes)
181 }
182
183 // Display dereferenced value.
184 switch {
185 case nilFound == true:
186 f.fs.Write(nilAngleBytes)
187
188 case cycleFound == true:
189 f.fs.Write(circularShortBytes)
190
191 default:
192 f.ignoreNextType = true
193 f.format(ve)
194 }
195}
196
197// format is the main workhorse for providing the Formatter interface. It
198// uses the passed reflect value to figure out what kind of object we are
199// dealing with and formats it appropriately. It is a recursive function,
200// however circular data structures are detected and handled properly.
201func (f *formatState) format(v reflect.Value) {
202 // Handle invalid reflect values immediately.
203 kind := v.Kind()
204 if kind == reflect.Invalid {
205 f.fs.Write(invalidAngleBytes)
206 return
207 }
208
209 // Handle pointers specially.
210 if kind == reflect.Ptr {
211 f.formatPtr(v)
212 return
213 }
214
215 // Print type information unless already handled elsewhere.
216 if !f.ignoreNextType && f.fs.Flag('#') {
217 f.fs.Write(openParenBytes)
218 f.fs.Write([]byte(v.Type().String()))
219 f.fs.Write(closeParenBytes)
220 }
221 f.ignoreNextType = false
222
223 // Call Stringer/error interfaces if they exist and the handle methods
224 // flag is enabled.
225 if !f.cs.DisableMethods {
226 if (kind != reflect.Invalid) && (kind != reflect.Interface) {
227 if handled := handleMethods(f.cs, f.fs, v); handled {
228 return
229 }
230 }
231 }
232
233 switch kind {
234 case reflect.Invalid:
235 // Do nothing. We should never get here since invalid has already
236 // been handled above.
237
238 case reflect.Bool:
239 printBool(f.fs, v.Bool())
240
241 case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
242 printInt(f.fs, v.Int(), 10)
243
244 case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
245 printUint(f.fs, v.Uint(), 10)
246
247 case reflect.Float32:
248 printFloat(f.fs, v.Float(), 32)
249
250 case reflect.Float64:
251 printFloat(f.fs, v.Float(), 64)
252
253 case reflect.Complex64:
254 printComplex(f.fs, v.Complex(), 32)
255
256 case reflect.Complex128:
257 printComplex(f.fs, v.Complex(), 64)
258
259 case reflect.Slice:
260 if v.IsNil() {
261 f.fs.Write(nilAngleBytes)
262 break
263 }
264 fallthrough
265
266 case reflect.Array:
267 f.fs.Write(openBracketBytes)
268 f.depth++
269 if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
270 f.fs.Write(maxShortBytes)
271 } else {
272 numEntries := v.Len()
273 for i := 0; i < numEntries; i++ {
274 if i > 0 {
275 f.fs.Write(spaceBytes)
276 }
277 f.ignoreNextType = true
278 f.format(f.unpackValue(v.Index(i)))
279 }
280 }
281 f.depth--
282 f.fs.Write(closeBracketBytes)
283
284 case reflect.String:
285 f.fs.Write([]byte(v.String()))
286
287 case reflect.Interface:
288 // The only time we should get here is for nil interfaces due to
289 // unpackValue calls.
290 if v.IsNil() {
291 f.fs.Write(nilAngleBytes)
292 }
293
294 case reflect.Ptr:
295 // Do nothing. We should never get here since pointers have already
296 // been handled above.
297
298 case reflect.Map:
299 // nil maps should be indicated as different than empty maps
300 if v.IsNil() {
301 f.fs.Write(nilAngleBytes)
302 break
303 }
304
305 f.fs.Write(openMapBytes)
306 f.depth++
307 if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
308 f.fs.Write(maxShortBytes)
309 } else {
310 keys := v.MapKeys()
311 if f.cs.SortKeys {
312 sortValues(keys, f.cs)
313 }
314 for i, key := range keys {
315 if i > 0 {
316 f.fs.Write(spaceBytes)
317 }
318 f.ignoreNextType = true
319 f.format(f.unpackValue(key))
320 f.fs.Write(colonBytes)
321 f.ignoreNextType = true
322 f.format(f.unpackValue(v.MapIndex(key)))
323 }
324 }
325 f.depth--
326 f.fs.Write(closeMapBytes)
327
328 case reflect.Struct:
329 numFields := v.NumField()
330 f.fs.Write(openBraceBytes)
331 f.depth++
332 if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
333 f.fs.Write(maxShortBytes)
334 } else {
335 vt := v.Type()
336 for i := 0; i < numFields; i++ {
337 if i > 0 {
338 f.fs.Write(spaceBytes)
339 }
340 vtf := vt.Field(i)
341 if f.fs.Flag('+') || f.fs.Flag('#') {
342 f.fs.Write([]byte(vtf.Name))
343 f.fs.Write(colonBytes)
344 }
345 f.format(f.unpackValue(v.Field(i)))
346 }
347 }
348 f.depth--
349 f.fs.Write(closeBraceBytes)
350
351 case reflect.Uintptr:
352 printHexPtr(f.fs, uintptr(v.Uint()))
353
354 case reflect.UnsafePointer, reflect.Chan, reflect.Func:
355 printHexPtr(f.fs, v.Pointer())
356
357 // There were not any other types at the time this code was written, but
358 // fall back to letting the default fmt package handle it if any get added.
359 default:
360 format := f.buildDefaultFormat()
361 if v.CanInterface() {
362 fmt.Fprintf(f.fs, format, v.Interface())
363 } else {
364 fmt.Fprintf(f.fs, format, v.String())
365 }
366 }
367}
368
369// Format satisfies the fmt.Formatter interface. See NewFormatter for usage
370// details.
371func (f *formatState) Format(fs fmt.State, verb rune) {
372 f.fs = fs
373
374 // Use standard formatting for verbs that are not v.
375 if verb != 'v' {
376 format := f.constructOrigFormat(verb)
377 fmt.Fprintf(fs, format, f.value)
378 return
379 }
380
381 if f.value == nil {
382 if fs.Flag('#') {
383 fs.Write(interfaceBytes)
384 }
385 fs.Write(nilAngleBytes)
386 return
387 }
388
389 f.format(reflect.ValueOf(f.value))
390}
391
392// newFormatter is a helper function to consolidate the logic from the various
393// public methods which take varying config states.
394func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter {
395 fs := &formatState{value: v, cs: cs}
396 fs.pointers = make(map[uintptr]int)
397 return fs
398}
399
400/*
401NewFormatter returns a custom formatter that satisfies the fmt.Formatter
402interface. As a result, it integrates cleanly with standard fmt package
403printing functions. The formatter is useful for inline printing of smaller data
404types similar to the standard %v format specifier.
405
406The custom formatter only responds to the %v (most compact), %+v (adds pointer
407addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb
408combinations. Any other verbs such as %x and %q will be sent to the the
409standard fmt package for formatting. In addition, the custom formatter ignores
410the width and precision arguments (however they will still work on the format
411specifiers not handled by the custom formatter).
412
413Typically this function shouldn't be called directly. It is much easier to make
414use of the custom formatter by calling one of the convenience functions such as
415Printf, Println, or Fprintf.
416*/
417func NewFormatter(v interface{}) fmt.Formatter {
418 return newFormatter(&Config, v)
419}
diff --git a/vendor/github.com/davecgh/go-spew/spew/spew.go b/vendor/github.com/davecgh/go-spew/spew/spew.go
new file mode 100644
index 0000000..32c0e33
--- /dev/null
+++ b/vendor/github.com/davecgh/go-spew/spew/spew.go
@@ -0,0 +1,148 @@
1/*
2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17package spew
18
19import (
20 "fmt"
21 "io"
22)
23
24// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
25// passed with a default Formatter interface returned by NewFormatter. It
26// returns the formatted string as a value that satisfies error. See
27// NewFormatter for formatting details.
28//
29// This function is shorthand for the following syntax:
30//
31// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b))
32func Errorf(format string, a ...interface{}) (err error) {
33 return fmt.Errorf(format, convertArgs(a)...)
34}
35
36// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
37// passed with a default Formatter interface returned by NewFormatter. It
38// returns the number of bytes written and any write error encountered. See
39// NewFormatter for formatting details.
40//
41// This function is shorthand for the following syntax:
42//
43// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b))
44func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
45 return fmt.Fprint(w, convertArgs(a)...)
46}
47
48// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
49// passed with a default Formatter interface returned by NewFormatter. It
50// returns the number of bytes written and any write error encountered. See
51// NewFormatter for formatting details.
52//
53// This function is shorthand for the following syntax:
54//
55// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b))
56func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
57 return fmt.Fprintf(w, format, convertArgs(a)...)
58}
59
60// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
61// passed with a default Formatter interface returned by NewFormatter. See
62// NewFormatter for formatting details.
63//
64// This function is shorthand for the following syntax:
65//
66// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b))
67func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
68 return fmt.Fprintln(w, convertArgs(a)...)
69}
70
71// Print is a wrapper for fmt.Print that treats each argument as if it were
72// passed with a default Formatter interface returned by NewFormatter. It
73// returns the number of bytes written and any write error encountered. See
74// NewFormatter for formatting details.
75//
76// This function is shorthand for the following syntax:
77//
78// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b))
79func Print(a ...interface{}) (n int, err error) {
80 return fmt.Print(convertArgs(a)...)
81}
82
83// Printf is a wrapper for fmt.Printf that treats each argument as if it were
84// passed with a default Formatter interface returned by NewFormatter. It
85// returns the number of bytes written and any write error encountered. See
86// NewFormatter for formatting details.
87//
88// This function is shorthand for the following syntax:
89//
90// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b))
91func Printf(format string, a ...interface{}) (n int, err error) {
92 return fmt.Printf(format, convertArgs(a)...)
93}
94
95// Println is a wrapper for fmt.Println that treats each argument as if it were
96// passed with a default Formatter interface returned by NewFormatter. It
97// returns the number of bytes written and any write error encountered. See
98// NewFormatter for formatting details.
99//
100// This function is shorthand for the following syntax:
101//
102// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b))
103func Println(a ...interface{}) (n int, err error) {
104 return fmt.Println(convertArgs(a)...)
105}
106
107// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
108// passed with a default Formatter interface returned by NewFormatter. It
109// returns the resulting string. See NewFormatter for formatting details.
110//
111// This function is shorthand for the following syntax:
112//
113// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b))
114func Sprint(a ...interface{}) string {
115 return fmt.Sprint(convertArgs(a)...)
116}
117
118// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
119// passed with a default Formatter interface returned by NewFormatter. It
120// returns the resulting string. See NewFormatter for formatting details.
121//
122// This function is shorthand for the following syntax:
123//
124// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b))
125func Sprintf(format string, a ...interface{}) string {
126 return fmt.Sprintf(format, convertArgs(a)...)
127}
128
129// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
130// were passed with a default Formatter interface returned by NewFormatter. It
131// returns the resulting string. See NewFormatter for formatting details.
132//
133// This function is shorthand for the following syntax:
134//
135// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b))
136func Sprintln(a ...interface{}) string {
137 return fmt.Sprintln(convertArgs(a)...)
138}
139
140// convertArgs accepts a slice of arguments and returns a slice of the same
141// length with each argument converted to a default spew Formatter interface.
142func convertArgs(args []interface{}) (formatters []interface{}) {
143 formatters = make([]interface{}, len(args))
144 for index, arg := range args {
145 formatters[index] = NewFormatter(arg)
146 }
147 return formatters
148}