-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse.go
43 lines (33 loc) · 919 Bytes
/
parse.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
package fcm
import (
"encoding/json"
"fmt"
"net/http"
)
func parseFcmResponse(resp *http.Response) (*response, error) {
// Defers
defer resp.Body.Close()
// Check statusCode from resp
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("statusCode: %d error: %s", resp.StatusCode, resp.Status)
}
// Create response
response := new(response)
response.StatusCode = resp.StatusCode
response.RetryAfter = resp.Header.Get("Retry-After")
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
return nil, err
}
return response, nil
}
func parseTokenDetails(resp *http.Response) (*tokenDetails, error) {
// Defers
defer resp.Body.Close()
// Create tokenDetails and decode
tokenDetails := new(tokenDetails)
tokenDetails.StatusCode = resp.StatusCode
if err := json.NewDecoder(resp.Body).Decode(tokenDetails); err != nil {
return nil, err
}
return tokenDetails, nil
}