-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli_utils.go
45 lines (39 loc) · 1.06 KB
/
cli_utils.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
/*
* Copyright (c) 2024 Johan Stenstam, [email protected]
*/
package tapir
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func (api *ApiClient) SendPing(pingcount int, dieOnError bool) (PingResponse, error) {
data := PingPost{
Msg: "One ping to rule them all and in the darkness bing them.",
Pings: pingcount,
}
_, buf, err := api.RequestNG(http.MethodPost, "/ping", data, dieOnError)
if err != nil {
return PingResponse{}, err
}
var pr PingResponse
err = json.Unmarshal(buf, &pr)
if err != nil {
log.Printf("Error parsing JSON for PingResponse: %s", string(buf))
log.Fatalf("Error from json.Unmarshal PingResponse: %v\n", err)
}
return pr, nil
}
func (api *ApiClient) ShowApi() {
_, buf, _ := api.RequestNG(http.MethodGet, "/show/api", nil, true)
var sar ShowAPIresponse
err := json.Unmarshal(buf, &sar)
if err != nil {
log.Printf("Error parsing JSON for ShowAPIResponse: %s", string(buf))
log.Fatalf("Error from unmarshal of ShowAPIresponse: %v\n", err)
}
for _, ep := range sar.Data[1:] {
fmt.Printf("%s\n", ep)
}
}