| 70 | } |
| 71 | |
| 72 | func Example_iface() { |
| 73 | doc := CustomDoc{ |
| 74 | a: "initial value for a", |
| 75 | b: "initial value for b", |
| 76 | // no extra values |
| 77 | } |
| 78 | |
| 79 | pointerA, err := jsonpointer.New("/propA") |
| 80 | if err != nil { |
| 81 | fmt.Println(err) |
| 82 | |
| 83 | return |
| 84 | } |
| 85 | |
| 86 | // get the initial value for a |
| 87 | propA, kind, err := pointerA.Get(doc) |
| 88 | if err != nil { |
| 89 | fmt.Println(err) |
| 90 | |
| 91 | return |
| 92 | } |
| 93 | fmt.Printf("propA (%v): %v\n", kind, propA) |
| 94 | |
| 95 | pointerB, err := jsonpointer.New("/propB") |
| 96 | if err != nil { |
| 97 | fmt.Println(err) |
| 98 | |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | // get the initial value for b |
| 103 | propB, kind, err := pointerB.Get(doc) |
| 104 | if err != nil { |
| 105 | fmt.Println(err) |
| 106 | |
| 107 | return |
| 108 | } |
| 109 | fmt.Printf("propB (%v): %v\n", kind, propB) |
| 110 | |
| 111 | pointerC, err := jsonpointer.New("/extra") |
| 112 | if err != nil { |
| 113 | fmt.Println(err) |
| 114 | |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | // not found yet |
| 119 | _, _, err = pointerC.Get(doc) |
| 120 | fmt.Printf("propC: %v\n", err) |
| 121 | |
| 122 | _, err = pointerA.Set(&doc, "new value for a") // doc is updated in place |
| 123 | if err != nil { |
| 124 | fmt.Println(err) |
| 125 | |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | _, err = pointerB.Set(&doc, "new value for b") |