-
Notifications
You must be signed in to change notification settings - Fork 18
/
extensions.go
46 lines (39 loc) · 1.08 KB
/
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
40
41
42
43
44
45
46
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"`
NewSubscriptions map[string]Subscription `json:"newSubscriptions"`
} `json:"subscription"`
}
// Subscription represents AWS AppSync subscription mqtt topic
type Subscription struct {
Topic string `json:"topic"`
ExpireTime interface{} `json:"expireTime"`
}
// 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
}