-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_debug.go
More file actions
49 lines (42 loc) · 1.08 KB
/
app_debug.go
File metadata and controls
49 lines (42 loc) · 1.08 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
package main
import (
"encoding/json"
"fmt"
"log"
)
// FetchDebugLogs calls GET /debug/logs
func (a *App) FetchDebugLogs() string {
url := fmt.Sprintf("%s/debug/logs", GetNodeBaseUrl())
body, err := get(url)
if err != nil {
log.Printf("Error fetching debug logs: %v", err)
resp := APIResponse{
Success: false,
Error: err.Error(),
Data: []interface{}{}, // always valid JSON array
}
jsonBytes, _ := json.Marshal(resp)
return string(jsonBytes)
}
// Wrap the body inside APIResponse
var parsed interface{}
if err := json.Unmarshal([]byte(body), &parsed); err != nil {
parsed = []interface{}{}
}
resp := APIResponse{
Success: true,
Data: parsed,
}
jsonBytes, _ := json.Marshal(resp)
return string(jsonBytes)
}
// AddDebugLog calls POST /debug/log with a full DebugLogEntry
func (a *App) AddDebugLog(entry DebugLogEntry) string {
url := fmt.Sprintf("%s/debug/log", GetNodeBaseUrl())
body, err := post(url, entry)
if err != nil {
log.Printf("Error adding debug log: %v", err)
return fmt.Sprintf("Error adding debug log: %v", err)
}
return body
}