-
Notifications
You must be signed in to change notification settings - Fork 7
/
riskfactors.go
59 lines (55 loc) · 1.27 KB
/
riskfactors.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
package infermedica
import (
"encoding/json"
"net/http"
"time"
)
type RiskFactorRes struct {
ID string `json:"id"`
Name string `json:"name"`
CommonName string `json:"common_name"`
SexFilter SexFilter `json:"sex_filter"`
Category string `json:"category"`
Seriousness string `json:"seriousness"`
ImageURL string `json:"image_url"`
ImageSource string `json:"image_source"`
Question string `json:"question"`
}
func (a *App) RiskFactors() (*[]RiskFactorRes, error) {
req, err := a.prepareRequest("GET", "risk_factors", nil)
if err != nil {
return nil, err
}
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := []RiskFactorRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}
func (a *App) RiskFactorByID(id string) (*RiskFactorRes, error) {
req, err := a.prepareRequest("GET", "risk_factors/"+id, nil)
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 := RiskFactorRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}