-
Notifications
You must be signed in to change notification settings - Fork 1
/
response.go
59 lines (49 loc) · 969 Bytes
/
response.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package ghc
import (
"bytes"
"encoding/json"
"github.com/Jeffail/gabs"
)
// Model ...
type Model interface {
Table() string
Schema() []string
}
// Data ...
type Data struct {
container *gabs.Container
}
// Container ...
type Container struct {
v *gabs.Container
}
// To ...
func (c *Container) To(t interface{}) error {
if c.v.Data() == nil {
return nil
}
return json.NewDecoder(bytes.NewBuffer(c.v.Bytes())).Decode(&t)
}
// Path ...
func (d *Data) Path(p string) *Container {
return &Container{v: d.container.Path(p)}
}
// Container ...
func (d *Data) Container() *gabs.Container {
return d.container
}
// UnmarshalJSON ...
func (d *Data) UnmarshalJSON(db []byte) error {
c, err := gabs.ParseJSON(db)
if err != nil {
return err
}
d.container = c
return nil
}
// Response ...
type Response struct {
Data *Data `json:"data,omitempty"`
Errors []interface{} `json:"errors,omitempty"`
Subscription chan interface{}
}