-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (48 loc) · 1.09 KB
/
main.go
File metadata and controls
59 lines (48 loc) · 1.09 KB
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 main
import (
"encoding/json"
"net/http"
"fmt"
)
type ErrorModel struct {
Code int64 `json:"code"`
Message string `json:"message"`
}
type HealthModel struct{
Status string `json:"status"`
Message string `json:"message"`
Version string `json:"version"`
}
func main() {
baseURL:= "https://api.amerandish.com/v1";
actionURL:= "/speech/healthcheck";
authKey:= "<YOUR_API_KEY>";
url := baseURL + actionURL;
req, err := http.NewRequest("GET", url, nil);
if(err != nil){
fmt.Printf("request error: %v",err)
return
}
req.Header.Add("Authorization", fmt.Sprintf("bearer %v", authKey));
client := &http.Client{}
res, err:= client.Do(req)
if(err != nil){
fmt.Printf("parse error: %v",err)
return
}
defer res.Body.Close()
if(res.StatusCode == 200){
// success
jsonBody := new(HealthModel)
fmt.Println(res.StatusCode)
json.NewDecoder(res.Body).Decode(jsonBody)
fmt.Println(jsonBody)
}else{
// error
jsonBody := new(ErrorModel)
fmt.Println(res.StatusCode)
json.NewDecoder(res.Body).Decode(jsonBody)
fmt.Println(res.Body)
fmt.Println(jsonBody.Message)
}
}