Skip to content

Commit dd92c09

Browse files
authored
feat: support http debug (#6)
Signed-off-by: Young Xu <xuthus5@gmail.com>
1 parent 85c7b61 commit dd92c09

File tree

9 files changed

+54
-3
lines changed

9 files changed

+54
-3
lines changed

app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type App struct {
3535
db *bolt.DB
3636
connects sync.Map
3737
logger *Logger
38+
debug bool
3839
}
3940

4041
// NewApp creates a new App application struct
@@ -61,6 +62,12 @@ func NewApp() *App {
6162
// so we can call the runtime methods
6263
func (app *App) startup(ctx context.Context) {
6364
app.ctx = ctx
65+
setting, err := app.GetSetting()
66+
if err != nil {
67+
app.logger.Error("get setting failed", "reason", err)
68+
} else {
69+
app.debug = setting.Debug
70+
}
6471
}
6572

6673
func (app *App) shutdown(ctx context.Context) {
@@ -177,6 +184,7 @@ func (app *App) GetConnect(name string) (*ConnectConfig, error) {
177184
}
178185

179186
func (app *App) UpdateSetting(settings *AppSetting) error {
187+
app.debug = settings.Debug
180188
data, err := json.Marshal(settings)
181189
if err != nil {
182190
app.logger.Error("update settings failed", "reason", err)
@@ -218,6 +226,9 @@ func (app *App) DialConnect(name string) ([]string, error) {
218226
app.logger.Error("dial connect failed: find connect config failed", "reason", err)
219227
return nil, err
220228
}
229+
if app.debug {
230+
cc.debug = true
231+
}
221232
httpClient, err := NewHttpClient(cc)
222233
if err != nil {
223234
app.logger.Error("dial connect failed: create http client failed", "reason", err)

data_struct.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ type ConnectConfig struct {
3030
EnableAuth bool `json:"enable_auth"`
3131
Username string `json:"username"`
3232
Password string `json:"password"`
33+
debug bool `json:"-"`
3334
}
3435

3536
var defaultAppSetting = &AppSetting{
3637
Language: "en",
3738
ThemeMode: "light",
3839
MaxHistoryCount: 100,
3940
DataDirectory: "./data",
41+
Debug: false,
4042
}
4143

4244
type AppSetting struct {
@@ -45,6 +47,7 @@ type AppSetting struct {
4547
CustomFont string `json:"custom_font"`
4648
MaxHistoryCount int `json:"max_history_count"`
4749
DataDirectory string `json:"data_dir"`
50+
Debug bool `json:"debug"`
4851
}
4952

5053
func (as *AppSetting) Marshal() []byte {
@@ -85,8 +88,8 @@ type ExecuteResponse struct {
8588
type History struct {
8689
ID string `json:"id"`
8790
Query string `json:"query"`
88-
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
89-
ExecutionTime float64 `json:"execution_time"` // Execution time in milliseconds
91+
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
92+
ExecutionTime float64 `json:"execution_time"` // Execution time in milliseconds
9093
Database string `json:"database"`
9194
RetentionPolicy string `json:"retention_policy"`
9295
Success bool `json:"success"`

frontend/src/components/Settings.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262
/>
6363
<span class="setting-hint">{{ $t('settings.dataDirectoryHint') }}</span>
6464
</div>
65+
66+
<div class="setting-group">
67+
<label class="setting-label setting-checkbox-label">
68+
<input
69+
v-model="localSettings.debug"
70+
type="checkbox"
71+
class="setting-checkbox"
72+
/>
73+
<span>{{ $t('settings.debug') }}</span>
74+
</label>
75+
<span class="setting-hint">{{ $t('settings.debugHint') }}</span>
76+
</div>
6577
</div>
6678

6779
<div class="settings-footer">
@@ -261,4 +273,19 @@ const handleReset = () => {
261273
.btn-secondary:hover {
262274
background: var(--bg-hover);
263275
}
276+
277+
.setting-checkbox-label {
278+
display: flex;
279+
align-items: center;
280+
gap: 8px;
281+
cursor: pointer;
282+
user-select: none;
283+
}
284+
285+
.setting-checkbox {
286+
width: 18px;
287+
height: 18px;
288+
cursor: pointer;
289+
accent-color: #3b82f6;
290+
}
264291
</style>

frontend/src/composables/useSettings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const DEFAULT_SETTINGS: AppSettings = {
99
customFont: "",
1010
maxHistoryCount: 50,
1111
dataDirectory: "./data",
12+
debug: false,
1213
}
1314

1415
// Data transformation utilities
@@ -19,6 +20,7 @@ const toBackendSettings = (settings: AppSettings): main.AppSetting => {
1920
custom_font: settings.customFont,
2021
max_history_count: settings.maxHistoryCount,
2122
data_dir: settings.dataDirectory,
23+
debug: settings.debug,
2224
}
2325
}
2426

@@ -29,6 +31,7 @@ const fromBackendSettings = (backendSettings: main.AppSetting): AppSettings => {
2931
customFont: backendSettings.custom_font || "",
3032
maxHistoryCount: backendSettings.max_history_count,
3133
dataDirectory: backendSettings.data_dir,
34+
debug: backendSettings.debug || false,
3235
}
3336
}
3437

frontend/src/locales/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export default {
9999
customFontHint: 'Enter custom font family names (comma-separated). Leave empty to use default fonts.',
100100
maxHistoryCount: 'Max History Count',
101101
dataDirectory: 'Data Directory',
102+
debug: 'Enable Debug Mode',
103+
debugHint: 'Enable debug mode to see detailed logs and diagnostic information',
102104
resetToDefaults: 'Reset to Defaults',
103105
save: 'Save',
104106
themeLight: 'Light',

frontend/src/locales/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export default {
9999
customFontHint: '输入自定义字体名称(用逗号分隔)。留空则使用默认字体。',
100100
maxHistoryCount: '最大历史记录数',
101101
dataDirectory: '数据目录',
102+
debug: '开启调试模式',
103+
debugHint: '启用调试模式以查看详细的日志和诊断信息',
102104
resetToDefaults: '重置为默认值',
103105
save: '保存',
104106
themeLight: '浅色',

frontend/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ export interface AppSettings {
7474
customFont: string
7575
maxHistoryCount: number
7676
dataDirectory: string
77+
debug: boolean
7778
}

frontend/wailsjs/go/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export namespace main {
66
custom_font: string;
77
max_history_count: number;
88
data_dir: string;
9+
debug: boolean;
910

1011
static createFrom(source: any = {}) {
1112
return new AppSetting(source);
@@ -18,6 +19,7 @@ export namespace main {
1819
this.custom_font = source["custom_font"];
1920
this.max_history_count = source["max_history_count"];
2021
this.data_dir = source["data_dir"];
22+
this.debug = source["debug"];
2123
}
2224
}
2325
export class ConnectConfig {

http_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func NewHttpClient(cfg *ConnectConfig) (HttpClient, error) {
246246
client.HostPort = schema + "://" + cfg.Address
247247

248248
client.client.Transport = transport
249-
client.SetDebug(true)
249+
client.SetDebug(cfg.debug)
250250
return client, nil
251251
}
252252

0 commit comments

Comments
 (0)