forked from sony/appsync-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions.go
39 lines (33 loc) · 862 Bytes
/
extensions.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
package appsync
import (
"encoding/json"
"fmt"
"github.com/sony/appsync-client-go/graphql"
)
// Extensions represents AWS AppSync subscription response extensions
type Extensions struct {
Subscription struct {
Version string `json:"version"`
MqttConnections []struct {
URL string `json:"url"`
Topics []string `json:"topics"`
Client string `json:"client"`
} `json:"mqttConnections"`
} `json:"subscription"`
}
// NewExtensions returns Extensions instance
func NewExtensions(response *graphql.Response) (*Extensions, error) {
j, ok := (*response.Extensions).(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Extensions is invalid")
}
b, err := json.Marshal(j)
if err != nil {
return nil, err
}
ext := new(Extensions)
if err := json.Unmarshal(b, ext); err != nil {
return nil, err
}
return ext, nil
}