forked from huandu/facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_result.go
52 lines (41 loc) · 1.03 KB
/
batch_result.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
// A facebook graph api client in go.
// https://github.com/huandu/facebook/
//
// Copyright 2012, Huan Du
// Licensed under the MIT license
// https://github.com/huandu/facebook/blob/master/LICENSE
package facebook
import (
"encoding/json"
"net/http"
)
type batchResultHeader struct {
Name string `facebook:",required"`
Value string `facebook:",required"`
}
type batchResultData struct {
Code int `facebook:",required"`
Headers []batchResultHeader `facebook:",required"`
Body string `facebook:",required"`
}
func newBatchResult(res Result) (*BatchResult, error) {
var data batchResultData
err := res.Decode(&data)
if err != nil {
return nil, err
}
result := &BatchResult{
StatusCode: data.Code,
Header: http.Header{},
Body: data.Body,
}
err = json.Unmarshal([]byte(result.Body), &result.Result)
if err != nil {
return nil, err
}
// add headers to result.
for _, header := range data.Headers {
result.Header.Add(header.Name, header.Value)
}
return result, nil
}