OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / github.com / stretchr / testify / vendor / github.com / stretchr / objx / doc.go
1 // objx - Go package for dealing with maps, slices, JSON and other data.
2 //
3 // Overview
4 //
5 // Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes
6 // a powerful `Get` method (among others) that allows you to easily and quickly get
7 // access to data within the map, without having to worry too much about type assertions,
8 // missing data, default values etc.
9 //
10 // Pattern
11 //
12 // Objx uses a preditable pattern to make access data from within `map[string]interface{}'s
13 // easy.
14 //
15 // Call one of the `objx.` functions to create your `objx.Map` to get going:
16 //
17 //     m, err := objx.FromJSON(json)
18 //
19 // NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong,
20 // the rest will be optimistic and try to figure things out without panicking.
21 //
22 // Use `Get` to access the value you're interested in.  You can use dot and array
23 // notation too:
24 //
25 //     m.Get("places[0].latlng")
26 //
27 // Once you have saught the `Value` you're interested in, you can use the `Is*` methods
28 // to determine its type.
29 //
30 //     if m.Get("code").IsStr() { /* ... */ }
31 //
32 // Or you can just assume the type, and use one of the strong type methods to
33 // extract the real value:
34 //
35 //     m.Get("code").Int()
36 //
37 // If there's no value there (or if it's the wrong type) then a default value
38 // will be returned, or you can be explicit about the default value.
39 //
40 //     Get("code").Int(-1)
41 //
42 // If you're dealing with a slice of data as a value, Objx provides many useful
43 // methods for iterating, manipulating and selecting that data.  You can find out more
44 // by exploring the index below.
45 //
46 // Reading data
47 //
48 // A simple example of how to use Objx:
49 //
50 //     // use MustFromJSON to make an objx.Map from some JSON
51 //     m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
52 //
53 //     // get the details
54 //     name := m.Get("name").Str()
55 //     age := m.Get("age").Int()
56 //
57 //     // get their nickname (or use their name if they
58 //     // don't have one)
59 //     nickname := m.Get("nickname").Str(name)
60 //
61 // Ranging
62 //
63 // Since `objx.Map` is a `map[string]interface{}` you can treat it as such.  For
64 // example, to `range` the data, do what you would expect:
65 //
66 //     m := objx.MustFromJSON(json)
67 //     for key, value := range m {
68 //
69 //       /* ... do your magic ... */
70 //
71 //     }
72 package objx