-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrequest.go
More file actions
37 lines (34 loc) · 723 Bytes
/
request.go
File metadata and controls
37 lines (34 loc) · 723 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
36
37
package capsolver_go
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func init() {
if ApiHost == "" {
ApiHost = DEFAULT_API_HOST
}
}
func request(uri string, solverRequest *capSolverRequest) (*CapSolverResponse, error) {
b, _ := json.Marshal(solverRequest)
resp, err := http.Post(fmt.Sprintf("%s%s", ApiHost, uri), "application/json", bytes.NewReader(b))
if err != nil {
return nil, err
}
defer func(Body io.ReadCloser) {
err = Body.Close()
if err != nil {
return
}
}(resp.Body)
b, _ = io.ReadAll(resp.Body)
capResponse := &CapSolverResponse{}
capResponse.Solution = &solution{}
err = json.Unmarshal(b, capResponse)
if err != nil {
return nil, err
}
return capResponse, nil
}