MCPcopy Index your code
hub / github.com/go-openapi/jsonpointer / Example_iface

Function Example_iface

iface_example_test.go:72–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70}
71
72func 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")

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
GetMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…