-
Notifications
You must be signed in to change notification settings - Fork 7
/
explain.go
47 lines (42 loc) · 1021 Bytes
/
explain.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
package infermedica
import (
"encoding/json"
"net/http"
"time"
)
type ExplainReq struct {
Sex Sex `json:"sex"`
Age int `json:"age"`
Target string `json:"target"`
Evidences []Evidence `json:"evidence"`
}
type ExplainRes struct {
SupportingEvidence []EvidenceItem `json:"supporting_evidence"`
ConflictingEvidence []EvidenceItem `json:"conflicting_evidence"`
UnconfirmedEvidence []EvidenceItem `json:"unconfirmed_evidence"`
}
type EvidenceItem struct {
ID string `json:"id"`
Name string `json:"name"`
CommonName string `json:"common_name"`
}
func (a *App) Explain(er ExplainReq) (*ExplainRes, error) {
req, err := a.prepareRequest("POST", "explain", er)
if err != nil {
return nil, err
}
client := &http.Client{
Timeout: time.Second * 5,
}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := ExplainRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}