-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-openapi%json-pointer.go
40 lines (35 loc) · 820 Bytes
/
go-openapi%json-pointer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package benchmark
import (
jsonpointer "github.com/go-openapi/jsonpointer"
)
type GoOpenAPIJSONPointer struct{}
func (GoOpenAPIJSONPointer) Get(doc interface{}, pointer string) (interface{}, error) {
ptr, err := jsonpointer.New(pointer)
if err != nil {
return nil, err
}
element, _, err := ptr.Get(doc)
if err != nil {
return nil, err
}
return element, nil
}
func (GoOpenAPIJSONPointer) Parse(pointer string) (Stringer, error) {
ptr, err := jsonpointer.New(pointer)
if err != nil {
return nil, err
}
return &ptr, err
}
func (GoOpenAPIJSONPointer) Set(document *interface{}, pointer string, value interface{}) error {
ptr, err := jsonpointer.New(pointer)
if err != nil {
return err
}
newDoc, err := ptr.Set(*document, value)
if err != nil {
return err
}
*document = newDoc
return nil
}