-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_cmd.go
More file actions
71 lines (68 loc) · 1.99 KB
/
status_cmd.go
File metadata and controls
71 lines (68 loc) · 1.99 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
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
)
func runShareplaneStatus(base string) error {
base = strings.TrimSpace(base)
if base == "" {
base = os.Getenv("SHAREPLANE_URL")
}
if base == "" {
base = "http://127.0.0.1:8080"
}
if !strings.HasPrefix(base, "http://") && !strings.HasPrefix(base, "https://") {
base = "http://" + base
}
base = strings.TrimSuffix(base, "/")
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(base + "/api/status")
if err != nil {
return fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("server returned %s: %s", resp.Status, strings.TrimSpace(string(body)))
}
var data apiStatusResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return fmt.Errorf("decode response: %w", err)
}
fmt.Printf("shareplane %s\n", data.Version)
fmt.Printf("Total bytes for file downloads: %d\n", data.TotalDownloadBytes)
fmt.Printf("Total bytes for file listings: %d\n", data.TotalListingBytes)
fmt.Println("Per file:")
for _, f := range data.Files {
fmt.Printf(" %s — %d×, %d bytes\n", f.Path, f.Count, f.Bytes)
}
fmt.Println("Per client (full / partial):")
for _, c := range data.Clients {
fmt.Printf(" %s\n", c.IP)
for _, f := range c.Files {
fmt.Printf(" %s %d full, %d partial\n", f.Path, f.Full, f.Partial)
}
}
if len(data.Activity) == 0 {
fmt.Println("Recent UI/API activity: (none)")
} else {
fmt.Println("Recent UI/API activity (newest first):")
for _, ev := range data.Activity {
fmt.Printf(" %s %s — %s — %s\n", ev.Time.Format(time.RFC3339), ev.IP, ev.Kind, ev.Detail)
}
}
if len(data.Events) == 0 {
fmt.Println("Event log: (none)")
} else {
fmt.Println("Event log (newest first):")
for _, ev := range data.Events {
fmt.Printf(" %s [%s] %s — %s\n", ev.Time.Format(time.RFC3339), ev.Type, ev.IP, ev.Detail)
}
}
return nil
}