-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.go
266 lines (242 loc) · 7.22 KB
/
app.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package main
import (
"ToDb/kit"
"ToDb/menu"
communication "ToDb/service"
"context"
"encoding/json"
"errors"
"net/http"
"strings"
"github.com/tidwall/gjson"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
// NewApp 创建一个新的 App 应用程序
func NewApp() *App {
return &App{}
}
// startup is called at application startup
// startup 在应用程序启动时调用
func (a *App) startup(ctx context.Context) {
// Perform your setup here
// 在这里执行初始化设置
a.ctx = ctx
menu.InitMenu(ctx, icon)
}
// domReady is called after the front-end dom has been loaded
// domReady 在前端Dom加载完毕后调用
func (a *App) domReady(ctx context.Context) {
// Add your action here
// 在这里添加你的操作
}
// beforeClose is called when the application is about to quit,
// either by clicking the window close button or calling runtime.Quit.
// Returning true will cause the application to continue,
// false will continue shutdown as normal.
// beforeClose在单击窗口关闭按钮或调用runtime.Quit即将退出应用程序时被调用.
// 返回 true 将导致应用程序继续,false 将继续正常关闭。
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
return false
}
// shutdown is called at application termination
// 在应用程序终止时被调用
func (a *App) shutdown(ctx context.Context) {
// Perform your teardown here
// 在此处做一些资源释放的操作
}
// ImportConn 导入
func (a *App) ImportConn() {
err := communication.General().ImportConn(a.ctx)
if err != nil {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", err.Error(), icon)
return
}
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", "导入成功", icon)
// 导入成功后窗口重载
runtime.WindowReload(a.ctx)
}
// ExportConn 导出
func (a *App) ExportConn() {
communication.General().ExportConn(a.ctx)
}
// TestConnection 测试连接
func (a *App) TestConnection(connectionInfo string) {
//var responseJson lib.JsonResponse
code, message := communication.Redis().RedisPing(connectionInfo)
if code != http.StatusOK {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", message, icon)
} else {
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", message, icon)
}
}
// Ok 确定按钮进行的操作
func (a App) Ok(connectionInfo string) string {
var responseJson kit.JsonResponse
code, message := communication.Redis().Ok(a.ctx, connectionInfo)
responseJson = kit.JsonResponse{
Code: code,
Message: message,
}
if code != http.StatusOK {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", message, icon)
}
runtime.WindowReload(a.ctx)
return responseJson.String()
}
// LoadingConnKey 加载已保存的连接信息
func (a *App) LoadingConnKey() string {
return communication.Redis().LoadingBaseHistoryInfo(a.ctx)
}
// LoadingConnInfo 获取链接信息详情
func (a *App) LoadingConnInfo(dbType, fileName string) string {
var code int
var message string
switch dbType {
case "redis":
code, message = communication.Redis().LoadingHistoryInfo(fileName)
default:
code = http.StatusNotFound
message = "暂不支持的数据库类型"
}
if code != http.StatusOK {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", message, icon)
return ""
}
return message
}
// LoadingDbResource 加载数据库资源消耗信息
func (a *App) LoadingDbResource(key string) string {
return communication.Redis().LoadingDbResource(a.ctx, key)
}
// ChangeRightWindowStyle 改变右侧窗口样式
func (a *App) ChangeRightWindowStyle(parentNode, nextParentNode, node string) string {
// 连接类型
connType := gjson.Get(parentNode, "connType").String()
// 文件名
fileName := gjson.Get(parentNode, "title").String()
switch connType {
case "redis":
default:
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", "暂不支持的数据库类型", icon)
return ""
}
// 获取db信息
dbId := gjson.Get(nextParentNode, "key").String()
// 获取指定的节点key
fullKey := gjson.Get(node, "fullStr").String()
// 指定的key数据类型
dataType, err := communication.Redis().GetValueType(a.ctx, fileName, dbId, fullKey)
if err != nil {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", err.Error(), icon)
}
return strings.ToLower(dataType)
}
// GetNodeData 获取节点数据
func (a *App) GetNodeData(connType, connName, nodeIdStr string) string {
strs := ""
var err error
switch connType {
case "redis":
// 获取redis节点数据
strs, err = communication.Redis().GetNodeData(a.ctx, connType, connName, nodeIdStr)
default:
err = errors.New("暂不支持此连接类型")
}
if err != nil {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", err.Error(), icon)
}
if strs == "null" {
strs = ""
}
return strs
}
// RedisGetData 从redis获取数据
func (a *App) RedisGetData(connType, connName, nodeIdStr, key string) string {
v := ""
switch connType {
case "redis":
// 获取redis节点数据
getValue, err := communication.Redis().RedisGetData(a.ctx, connType, connName, nodeIdStr, key)
if err != nil {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", err.Error(), icon)
return ""
}
_v, _ := json.Marshal(getValue)
v = string(_v)
default:
v = "暂不支持"
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", v, icon)
return v
}
return v
}
// RedisReName redis key重命名
func (a *App) RedisReName(connType, connName, nodeIdStr, oldKey, newKey string) {
v := ""
switch connType {
case "redis":
v = communication.Redis().RedisReName(a.ctx, connType, connName,
nodeIdStr, oldKey, newKey)
default:
v = "暂不支持"
}
if v != "success" {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", v, icon)
} else {
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", "修改成功", icon)
}
}
// RedisUpTtl 更新redis剩余时间
func (a *App) RedisUpTtl(connType, connName, nodeIdStr, key, ttlStr string) {
v := ""
switch connType {
case "redis":
v = communication.Redis().RedisUpTtl(a.ctx, connType, connName, nodeIdStr, key, ttlStr)
default:
v = "暂不支持"
}
if v != "success" {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", v, icon)
} else {
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", "修改成功", icon)
}
}
// RedisDelKey 删除键
func (a *App) RedisDelKey(connType, connName, nodeIdStr, key string) {
selection, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "删除",
Message: "确定删除该key吗?",
Buttons: []string{"Cancel", "Ok"},
})
if selection != "Ok" {
return
}
v := communication.Redis().RedisDel(a.ctx, connType, connName, nodeIdStr, key)
if v != "success" {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", v, icon)
} else {
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", "删除成功", icon)
}
}
// RedisSaveStringValue 更新redis值
func (a *App) RedisSaveStringValue(connType, connName, nodeIdStr, key, value, ttl string) {
var err error
switch connType {
case "redis":
err = communication.Redis().RedisUpdateStringValue(a.ctx, connType, connName,
nodeIdStr, key, value, ttl)
default:
err = errors.New("暂不支持")
}
if err != nil {
kit.DiaLogKit().DefaultDialog(a.ctx, "错误", err.Error(), icon)
} else {
kit.DiaLogKit().DefaultDialog(a.ctx, "成功", "修改成功", icon)
}
}