• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D30-Apr-2019108

LICENSEH A D30-Apr-20191 KiB

README.mdH A D30-Apr-20191.5 KiB

delete.goH A D30-Apr-20192.9 KiB

delete_test.goH A D30-Apr-20191.3 KiB

get.goH A D30-Apr-20192.2 KiB

get_test.goH A D30-Apr-20192 KiB

go.modH A D30-Apr-2019104

go.sumH A D30-Apr-2019185

parse.goH A D30-Apr-20191.3 KiB

parse_test.goH A D30-Apr-20191 KiB

pointer.goH A D30-Apr-20193.5 KiB

pointer_examples_test.goH A D30-Apr-2019693

pointer_test.goH A D30-Apr-2019971

set.goH A D30-Apr-20193.1 KiB

set_test.goH A D30-Apr-20191.8 KiB

sort.goH A D30-Apr-20191.1 KiB

sort_test.goH A D30-Apr-2019853

README.md

1# pointerstructure [![GoDoc](https://godoc.org/github.com/mitchellh/pointerstructure?status.svg)](https://godoc.org/github.com/mitchellh/pointerstructure)
2
3pointerstructure is a Go library for identifying a specific value within
4any Go structure using a string syntax.
5
6pointerstructure is based on
7[JSON Pointer (RFC 6901)](https://tools.ietf.org/html/rfc6901), but
8reimplemented for Go.
9
10The goal of pointerstructure is to provide a single, well-known format
11for addressing a specific value. This can be useful for user provided
12input on structures, diffs of structures, etc.
13
14## Features
15
16  * Get the value for an address
17
18  * Set the value for an address within an existing structure
19
20  * Delete the value at an address
21
22  * Sorting a list of addresses
23
24## Installation
25
26Standard `go get`:
27
28```
29$ go get github.com/mitchellh/pointerstructure
30```
31
32## Usage & Example
33
34For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/pointerstructure).
35
36A quick code example is shown below:
37
38```go
39complex := map[string]interface{}{
40	"alice": 42,
41	"bob": []interface{}{
42		map[string]interface{}{
43			"name": "Bob",
44		},
45	},
46}
47
48value, err := pointerstructure.Get(complex, "/bob/0/name")
49if err != nil {
50	panic(err)
51}
52
53fmt.Printf("%s", value)
54// Output:
55// Bob
56```
57
58Continuing the example above, you can also set values:
59
60```go
61value, err = pointerstructure.Set(complex, "/bob/0/name", "Alice")
62if err != nil {
63	panic(err)
64}
65
66value, err = pointerstructure.Get(complex, "/bob/0/name")
67if err != nil {
68	panic(err)
69}
70
71fmt.Printf("%s", value)
72// Output:
73// Alice
74```
75