/
checkin.go
39 lines (35 loc) · 1.13 KB
/
checkin.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
package ooapi
//
// CheckIn API
//
import (
"encoding/json"
"net/http"
"github.com/ooni/probe-engine/pkg/httpapi"
"github.com/ooni/probe-engine/pkg/model"
"github.com/ooni/probe-engine/pkg/runtimex"
)
// NewDescriptorCheckIn creates a new [httpapi.Descriptor] describing how
// to issue an HTTP call to the CheckIn API.
func NewDescriptorCheckIn(
config *model.OOAPICheckInConfig,
) *httpapi.Descriptor[*model.OOAPICheckInConfig, *model.OOAPICheckInResult] {
rawRequest, err := json.Marshal(config)
runtimex.PanicOnError(err, "json.Marshal failed unexpectedly")
return &httpapi.Descriptor[*model.OOAPICheckInConfig, *model.OOAPICheckInResult]{
Accept: httpapi.ApplicationJSON,
AcceptEncodingGzip: true, // we want a small response
Authorization: "",
ContentType: httpapi.ApplicationJSON,
LogBody: true,
MaxBodySize: 0,
Method: http.MethodPost,
Request: &httpapi.RequestDescriptor[*model.OOAPICheckInConfig]{
Body: rawRequest,
},
Response: &httpapi.JSONResponseDescriptor[model.OOAPICheckInResult]{},
Timeout: 0,
URLPath: "/api/v1/check-in",
URLQuery: nil,
}
}