-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathturn.go
More file actions
35 lines (32 loc) · 717 Bytes
/
turn.go
File metadata and controls
35 lines (32 loc) · 717 Bytes
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
package bot
import (
"context"
"encoding/json"
)
type Turn struct {
Url string `json:"url"`
Username string `json:"username"`
Credential string `json:"credential"`
}
func GetTurnServer(ctx context.Context, su *SafeUser) ([]*Turn, error) {
token, err := SignAuthenticationToken("GET", "/turn", "", su)
if err != nil {
return nil, err
}
body, err := Request(ctx, "GET", "/turn", nil, token)
if err != nil {
return nil, ServerError(ctx, err)
}
var resp struct {
Data []*Turn `json:"data"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, BadDataError(ctx)
}
if resp.Error.Code > 0 {
return nil, resp.Error
}
return resp.Data, nil
}