Skip to content

Commit 68a9a02

Browse files
authored
Merge pull request #402 from lazzyfu/dev
Dev
2 parents f018121 + 17d8f7b commit 68a9a02

74 files changed

Lines changed: 1401 additions & 433 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ goInsight/cmd/__debug_bin
3434
goInsight_windows.code-workspace
3535
goInsight-fe/node_modules
3636
goInsight-fe/yarn-error.log
37-
goInsight/config.yaml
3837
goInsight/dist/
3938
goInsight/goinsight/dist
4039
goinsight/bin/
@@ -45,7 +44,9 @@ github.goinsight.code-workspace
4544
# Backend
4645
backend/logs/
4746
backend/media/
48-
backend/web/dist/
47+
backend/web/dist/*
48+
!backend/web/dist/
49+
!backend/web/dist/index.html
4950
backend/code.code-workspace
5051

5152
# Frontend

backend/config.yaml

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,74 @@
11
# 应用配置
22
app:
3-
title: "GoInsight" # 网站Title
4-
listen_address: "localhost:8083" # 应用监听地址
5-
environment: "dev" # 环境设置,可选值为dev/prod
6-
secret_key: "A9$k!pZ3@rT7&xQ1#Lf8^Vm2*Ws6%Hd0" # 必须32位长度,应用密钥,请妥善保管
3+
listen_address: "localhost:8083" # 应用监听地址
4+
environment: "dev" # 环境设置,可选值为dev/prod,生产写prod
5+
secret_key: "A9$k!pZ3@rT7&xQ1#Lf8^Vm2*Ws6%Hd0" # 必须32位长度,用于登录认证、密码加密,请更换
76

87
crontab:
9-
sync_db_metas: "*/5 * * * *" # 每5分钟同步一次远程数据库库表元数据到本地数据库
8+
sync_db_metas: "*/5 * * * *" # 每5分钟同步一次远程数据库库表元数据到本地数据库
109

1110
# 日志配置
1211
log:
13-
level: "info" # 日志级别
14-
root_dir: "./logs" # 日志根目录
12+
level: "info" # 日志级别
13+
root_dir: "./logs" # 日志根目录
1514

16-
# MySQL数据库配置,用于存储应用数据
15+
# MySQL数据库配置,用于存储goinsight应用数据
1716
database:
18-
driver: "mysql" # 数据库驱动
19-
host: "127.0.0.1" # 数据库主机
20-
port: 3306 # 数据库端口
21-
database: "goinsight" # 数据库名称
22-
username: "goinsight_rw" # 数据库用户名
23-
password: "1234.Com!" # 数据库密码
24-
charset: "utf8mb4" # 数据库字符集
25-
max_idle_conns: 64 # 最大空闲连接数
26-
max_open_conns: 64 # 最大打开连接数
27-
conn_max_life_time: 3600 # 连接的最大存活时间
28-
conn_max_idle_time: 3600 # 连接的最大空闲时间
17+
driver: "mysql" # 数据库驱动
18+
host: "127.0.0.1" # 数据库主机
19+
port: 3306 # 数据库端口
20+
database: "goinsight" # 数据库名称
21+
username: "goinsight_rw" # 数据库用户名
22+
password: "1234.Com!" # 数据库密码
23+
charset: "utf8mb4" # 数据库字符集
24+
max_idle_conns: 64 # 最大空闲连接数
25+
max_open_conns: 64 # 最大打开连接数
26+
conn_max_life_time: 3600 # 连接的最大存活时间
27+
conn_max_idle_time: 3600 # 连接的最大空闲时间
2928

30-
# Redis配置,用于缓存应用数据
29+
# Redis配置
3130
redis:
32-
host: "127.0.0.1" # Redis主机
33-
port: 6379 # Redis端口
34-
password: "" # Redis密码
35-
db: 0
31+
host: "127.0.0.1" # Redis主机
32+
port: 6379 # Redis端口
33+
password: "1234.com" # Redis密码
34+
db: 0
3635

3736
# 数据查询配置
3837
das:
39-
max_execution_time: 600000 # 查询语句最大查询执行时间
40-
default_return_rows: 100 # 查询默认返回行数
41-
max_return_rows: 100 # 查询默认最大返回行数
42-
allowed_useragents: [
43-
"Chrome",
44-
"Firefox",
45-
"Safari",
46-
"Trident",
47-
"Presto",
48-
"Postman",
49-
] # 允许的UA
38+
max_execution_time: 600000 # 查询语句最大查询执行时间
39+
default_return_rows: 100 # 查询默认返回行数
40+
max_return_rows: 100 # 查询默认最大返回行数
5041

5142
# GitHub's Online Schema-migration Tool for MySQL
5243
# https://github.com/github/gh-ost
5344
ghost:
54-
path: "/usr/local/bin/gh-ost" # Gh-ost工具路径
55-
args: # Gh-ost工具参数列表
56-
[
57-
"--allow-on-master",
58-
"--assume-rbr",
59-
"--initially-drop-ghost-table",
60-
"--initially-drop-old-table",
61-
"-initially-drop-socket-file",
62-
"-exact-rowcount",
63-
"--approve-renamed-columns",
64-
"--concurrent-rowcount=false",
65-
"--chunk-size=800",
66-
]
45+
path: "/usr/local/bin/gh-ost" # Gh-ost工具路径
46+
args: # Gh-ost工具参数列表
47+
[
48+
"--allow-on-master",
49+
"--assume-rbr",
50+
"--initially-drop-ghost-table",
51+
"--initially-drop-old-table",
52+
"-initially-drop-socket-file",
53+
"-exact-rowcount",
54+
"--approve-renamed-columns",
55+
"--concurrent-rowcount=false",
56+
"--chunk-size=800",
57+
]
6758

6859
# 消息通知配置,用于工单消息推送
6960
notify:
70-
notice_url: "http://localhost:8083/"
71-
wechat:
72-
enable: true
73-
webhook: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1234"
74-
dingtalk:
75-
enable: false
76-
webhook: "https://oapi.dingtalk.com/robot/send?access_token=1234"
77-
keywords: "goinsight"
78-
mail:
79-
enable: false
80-
username: "xxx@163.com"
81-
password: "1234.com"
82-
host: "smtp.163.com"
83-
port: 465
61+
notice_url: "http://localhost:8083" # 消息通知和导出工单域名前缀
62+
wechat:
63+
enable: true
64+
webhook: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=123.com"
65+
dingtalk:
66+
enable: false
67+
webhook: "https://oapi.dingtalk.com/robot/send?access_token=1234"
68+
keywords: "goinsight"
69+
mail:
70+
enable: false
71+
username: "xxx@163.com"
72+
password: "1234.com"
73+
host: "smtp.163.com"
74+
port: 465
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package app
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/gin-gonic/gin"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestSetupStaticFiles_AllowsMissingAssets(t *testing.T) {
13+
gin.SetMode(gin.TestMode)
14+
15+
wd, err := os.Getwd()
16+
require.NoError(t, err)
17+
t.Cleanup(func() {
18+
require.NoError(t, os.Chdir(wd))
19+
})
20+
21+
tmp := t.TempDir()
22+
require.NoError(t, os.Chdir(tmp))
23+
24+
r := gin.New()
25+
err = setupStaticFiles(r)
26+
require.NoError(t, err)
27+
28+
_, err = os.Stat(filepath.Join(tmp, "media"))
29+
require.NoError(t, err)
30+
}

backend/internal/common/services/environment.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package services
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/lazzyfu/goinsight/internal/global"
@@ -44,10 +45,12 @@ func (s *AdminCreateEnvironmentService) Run() error {
4445
}
4546
result := tx.Create(&db)
4647
if result.Error != nil {
47-
mysqlErr := result.Error.(*mysql.MySQLError)
48-
switch mysqlErr.Number {
49-
case 1062:
50-
return fmt.Errorf("记录`%s`已存在", s.Name)
48+
var mysqlErr *mysql.MySQLError
49+
if errors.As(result.Error, &mysqlErr) {
50+
switch mysqlErr.Number {
51+
case 1062:
52+
return fmt.Errorf("记录`%s`已存在", s.Name)
53+
}
5154
}
5255
return result.Error
5356
}
@@ -65,10 +68,12 @@ func (s *AdminUpdateEnvironmentService) Run() error {
6568
"name": s.Name,
6669
})
6770
if result.Error != nil {
68-
mysqlErr := result.Error.(*mysql.MySQLError)
69-
switch mysqlErr.Number {
70-
case 1062:
71-
return fmt.Errorf("记录`%s`已存在", s.Name)
71+
var mysqlErr *mysql.MySQLError
72+
if errors.As(result.Error, &mysqlErr) {
73+
switch mysqlErr.Number {
74+
case 1062:
75+
return fmt.Errorf("记录`%s`已存在", s.Name)
76+
}
7277
}
7378
return result.Error
7479
}

backend/internal/common/services/instance.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package services
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67

78
"github.com/lazzyfu/goinsight/internal/global"
@@ -111,10 +112,12 @@ func (s *AdminCreateInstancesService) Run() error {
111112
result := tx.Create(&db)
112113

113114
if result.Error != nil {
114-
mysqlErr := result.Error.(*mysql.MySQLError)
115-
switch mysqlErr.Number {
116-
case 1062:
117-
return fmt.Errorf("使用类型为%s的%s:%d记录已存在", s.UseType, s.Hostname, s.Port)
115+
var mysqlErr *mysql.MySQLError
116+
if errors.As(result.Error, &mysqlErr) {
117+
switch mysqlErr.Number {
118+
case 1062:
119+
return fmt.Errorf("使用类型为%s的%s:%d记录已存在", s.UseType, s.Hostname, s.Port)
120+
}
118121
}
119122
return result.Error
120123
}
@@ -159,10 +162,12 @@ func (s *AdminUpdateInstancesService) Run() error {
159162
// 更新记录
160163
result := global.App.DB.Model(&models.InsightInstances{}).Where("id=?", s.ID).Updates(updates)
161164
if result.Error != nil {
162-
mysqlErr := result.Error.(*mysql.MySQLError)
163-
switch mysqlErr.Number {
164-
case 1062:
165-
return fmt.Errorf("使用类型为%s的%s:%d记录已存在", s.UseType, s.Hostname, s.Port)
165+
var mysqlErr *mysql.MySQLError
166+
if errors.As(result.Error, &mysqlErr) {
167+
switch mysqlErr.Number {
168+
case 1062:
169+
return fmt.Errorf("使用类型为%s的%s:%d记录已存在", s.UseType, s.Hostname, s.Port)
170+
}
166171
}
167172
return result.Error
168173
}
@@ -221,10 +226,12 @@ func (s *AdminCreateInstanceInspectParamsService) Run() error {
221226
result := tx.Create(&db)
222227

223228
if result.Error != nil {
224-
mysqlErr := result.Error.(*mysql.MySQLError)
225-
switch mysqlErr.Number {
226-
case 1062:
227-
return fmt.Errorf("实例审核参数`%s`已存在", s.Key)
229+
var mysqlErr *mysql.MySQLError
230+
if errors.As(result.Error, &mysqlErr) {
231+
switch mysqlErr.Number {
232+
case 1062:
233+
return fmt.Errorf("实例审核参数`%s`已存在", s.Key)
234+
}
228235
}
229236
return result.Error
230237
}

backend/internal/common/views/environment.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package views
22

33
import (
4-
"strconv"
5-
64
"github.com/lazzyfu/goinsight/pkg/response"
75

86
"github.com/lazzyfu/goinsight/internal/common/forms"
@@ -48,13 +46,16 @@ func AdminCreateEnvironmentView(c *gin.Context) {
4846
}
4947

5048
func AdminUpdateEnvironmentView(c *gin.Context) {
51-
id, _ := strconv.Atoi(c.Param("id"))
49+
id, ok := parseUint64Param(c, "id")
50+
if !ok {
51+
return
52+
}
5253
var form *forms.AdminUpdateEnvironmentForm = &forms.AdminUpdateEnvironmentForm{}
5354
if err := c.ShouldBind(&form); err == nil {
5455
service := services.AdminUpdateEnvironmentService{
5556
AdminUpdateEnvironmentForm: form,
5657
C: c,
57-
ID: uint64(id),
58+
ID: id,
5859
}
5960
err := service.Run()
6061
if err != nil {
@@ -68,10 +69,13 @@ func AdminUpdateEnvironmentView(c *gin.Context) {
6869
}
6970

7071
func AdminDeleteEnvironmentView(c *gin.Context) {
71-
id, _ := strconv.Atoi(c.Param("id"))
72+
id, ok := parseUint64Param(c, "id")
73+
if !ok {
74+
return
75+
}
7276
service := services.AdminDeleteEnvironmentService{
7377
C: c,
74-
ID: uint64(id),
78+
ID: id,
7579
}
7680
err := service.Run()
7781
if err != nil {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package views
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/lazzyfu/goinsight/pkg/response"
7+
8+
"github.com/gin-gonic/gin"
9+
)
10+
11+
func parseUint64Param(c *gin.Context, name string) (uint64, bool) {
12+
raw := c.Param(name)
13+
id, err := strconv.ParseUint(raw, 10, 64)
14+
if err != nil {
15+
response.ValidateFail(c, "非法参数: "+name)
16+
return 0, false
17+
}
18+
return id, true
19+
}

0 commit comments

Comments
 (0)