-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_id_documents_id_get.go
98 lines (85 loc) · 1.99 KB
/
event_id_documents_id_get.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package benchmark
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"time"
"github.com/tingtt/prc_hub_bench/infrastructure/externalapi/backend"
)
func EventsIdDocumentsIdGet(c *backend.Client, ctx context.Context, bearer string, eventId string, documentId string, wantedStatusCode int) (d time.Duration, err error) {
start := time.Now()
r, err := c.GetEventsIdDocumentsDocumentId(
ctx,
eventId,
documentId,
func(ctx context.Context, req *http.Request) error {
req.Header.Add("Authorization", "Bearer "+bearer)
return nil
},
)
d = time.Since(start)
if err != nil {
return
}
if r.StatusCode != wantedStatusCode {
err = fmt.Errorf("failed to request (GET /events/:id/documents/:document_id): expected %d, found %d", wantedStatusCode, r.StatusCode)
return
}
// Chceck response body
b, err := io.ReadAll(r.Body)
if err != nil {
return
}
// Unmarshal
document := EventDocument{}
err = json.Unmarshal(b, &document)
if err != nil {
return
}
err = document.validate()
if err != nil {
return
}
return
}
func eventsIdDocumentsIdGet(c *backend.Client, bearer string, eventId string, documentId string, wantedStatusCode int) (document EventDocument, err error) {
r, err := c.GetEventsIdDocumentsDocumentId(
context.Background(),
eventId,
documentId,
func(ctx context.Context, req *http.Request) error {
req.Header.Add("Authorization", "Bearer "+bearer)
return nil
},
)
if err != nil {
return
}
// log response
b, err := io.ReadAll(r.Body)
if err != nil {
return
}
err = writeFile("./.log/events_id_documents_id_GET_"+strconv.Itoa(r.StatusCode)+".json", b)
if err != nil {
return
}
// Check status code
if r.StatusCode != wantedStatusCode {
err = fmt.Errorf("failed to request (GET /events/:id/documents/:document_id): expected %d, found %d", wantedStatusCode, r.StatusCode)
return
}
// Unmarshal
err = json.Unmarshal(b, &document)
if err != nil {
return
}
err = document.validate()
if err != nil {
return
}
return
}