-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerEdit.go
More file actions
59 lines (50 loc) · 1.5 KB
/
HandlerEdit.go
File metadata and controls
59 lines (50 loc) · 1.5 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 example
import (
"fmt"
"time"
)
type DatabaseHandler struct {
ConnectionString string
LastAction string
log func(message ...any)
}
func (h *DatabaseHandler) Name() string { return "DatabaseConfig" }
func (h *DatabaseHandler) Label() string { return "Database Connection" }
func (h *DatabaseHandler) Value() string { return h.ConnectionString }
// SetLog receives the logger from DevTUI
func (h *DatabaseHandler) SetLog(logger func(message ...any)) {
h.log = logger
}
func (h *DatabaseHandler) Change(newValue string) {
// Ensure log is not nil (safe guard)
if h.log == nil {
h.log = func(message ...any) { fmt.Println(message...) }
}
switch newValue {
case "t":
h.LastAction = "test"
h.log("Testing database connection...")
time.Sleep(500 * time.Millisecond)
h.log("Connection test completed successfully")
case "b":
h.LastAction = "backup"
h.log("Starting database backup...")
time.Sleep(1000 * time.Millisecond)
h.log("Database backup completed successfully")
default:
// Regular connection string update
h.log("Validating Connection " + newValue)
time.Sleep(500 * time.Millisecond)
h.log("Testing database connectivity... " + newValue)
time.Sleep(500 * time.Millisecond)
h.log("Connection Database configured successfully " + newValue)
h.ConnectionString = newValue
}
}
// NEW: Add shortcut support
func (h *DatabaseHandler) Shortcuts() []map[string]string {
return []map[string]string{
{"t": "test connection"},
{"b": "backup database"},
}
}