Skip to content

Commit 37a5963

Browse files
committed
perf👌: Optimize go warnings
1 parent 69df1b3 commit 37a5963

Some content is hidden

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

41 files changed

+83
-87
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ Describe changes from the user side, and list all potential break changes or oth
6262

6363
- [ ] Doc is updated/provided or not needed
6464
- [ ] Demo is updated/provided or not needed
65-
- [ ] TypeScript definition is updated/provided or not needed
65+
- [ ] TypeScript's definition is updated/provided or not needed
6666
- [ ] Changelog is provided or not needed

.github/workflows/issue-labeled.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
token: ${{ secrets.ADMIN_TOKEN }}
4747
issue-number: ${{ github.event.issue.number }}
4848
body: |
49-
Hello @${{ github.event.issue.user.login }}, we use GitHub issues to trace bugs or discuss plans of Ant Design. So, please [don't ask usage questions](https://github.com/ant-design/ant-design/issues/2320) here. You can try to open a new discussion in [antd discussions](https://github.com/ant-design/ant-design/discussions), select `Q&A` to ask questions, also can ask questions on [Stack Overflow](http://stackoverflow.com/questions/tagged/antd) or [Segment Fault](https://segmentfault.com/t/antd), then apply tag `antd` and `react` to your question.
50-
你好 @${{ github.event.issue.user.login }},go-admin Issue 板块是用于 bug 反馈与需求讨论的地方。请[勿询问如何使用的问题](https://github.com/go-admin-te/ant-design/issues/699),你可以试着在 [antd discussions](https://github.com/ant-design/ant-design/discussions) 新开一个 discussion,选择 `Q&A` 类别进行提问,也可以在 [Stack Overflow](http://stackoverflow.com/questions/tagged/antd) 或者 [Segment Fault](https://segmentfault.com/t/antd) 中提问(记得添加 `antd` 和 `react` 标签哦~)。
49+
Hello @${{ github.event.issue.user.login }}, we use GitHub issues to trace bugs or discuss plans of Ant Design. So, please [don't ask usage questions](https://github.com/ant-design/ant-design/issues/2320) here. You can try to open a new discussion in [antd discussions](https://github.com/ant-design/ant-design/discussions), select `Q&A` to ask questions, also can ask questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/antd) or [Segment Fault](https://segmentfault.com/t/antd), then apply tag `antd` and `react` to your question.
50+
你好 @${{ github.event.issue.user.login }},go-admin Issue 板块是用于 bug 反馈与需求讨论的地方。请[勿询问如何使用的问题](https://github.com/go-admin-te/ant-design/issues/699),你可以试着在 [antd discussions](https://github.com/ant-design/ant-design/discussions) 新开一个 discussion,选择 `Q&A` 类别进行提问,也可以在 [Stack Overflow](https://stackoverflow.com/questions/tagged/antd) 或者 [Segment Fault](https://segmentfault.com/t/antd) 中提问(记得添加 `antd` 和 `react` 标签哦~)。
5151
- name: 3.x
5252
if: github.event.label.name == '3.x'
5353
uses: actions-cool/issues-helper@v3

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ config/settings.dev.yml.log
1717
config/settings.b.dev.yml
1818
cmd/migrate/migration/version-local/*
1919
!cmd/migrate/migration/version-local/doc.go
20-
*/.DS_Store
2120

2221
# go sum
2322
go.sum

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ vi ./config/settings.yml
158158
# 2. Confirm the log path
159159
```
160160

161-
:::tip ⚠️Note that this problem will occur if CGO is not installed in the windows environment;
161+
:::tip ⚠️Note that this problem will occur if CGO is not installed in the windows10+ environment;
162162

163163
```bash
164164
E:\go-admin>go build

app/admin/apis/go_admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ body{
1717
overflow-y:hidden
1818
}
1919
</style>
20-
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
20+
<script src="https://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
2121
<script type="text/javascript">
2222
window.onerror=function(){return true;}
2323
$(function(){

app/admin/models/casbin_rule.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package models
22

3-
//sys_casbin_rule
43
type CasbinRule struct {
54
ID uint `gorm:"primaryKey;autoIncrement"`
65
Ptype string `gorm:"size:512;uniqueIndex:unique_index"`

app/admin/models/initdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func ExecSql(db *gorm.DB, filePath string) error {
3131
fmt.Println(sqlList[i])
3232
continue
3333
}
34-
sql := strings.Replace(sqlList[i]+";", "\n", "", 0)
34+
sql := strings.Replace(sqlList[i]+";", "\n", "", -1)
3535
sql = strings.TrimSpace(sql)
3636
if err = db.Exec(sql).Error; err != nil {
3737
log.Printf("error sql: %s", sql)

app/admin/models/sys_api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type SysApi struct {
2727
models.ControlBy
2828
}
2929

30-
func (SysApi) TableName() string {
30+
func (*SysApi) TableName() string {
3131
return "sys_api"
3232
}
3333

@@ -44,14 +44,14 @@ func SaveSysApi(message storage.Messager) (err error) {
4444
var rb []byte
4545
rb, err = json.Marshal(message.GetValues())
4646
if err != nil {
47-
fmt.Errorf("json Marshal error, %s", err.Error())
47+
err = fmt.Errorf("json Marshal error, %v", err.Error())
4848
return err
4949
}
5050

5151
var l runtime.Routers
5252
err = json.Unmarshal(rb, &l)
5353
if err != nil {
54-
fmt.Errorf("json Unmarshal error, %s", err.Error())
54+
err = fmt.Errorf("json Unmarshal error, %s", err.Error())
5555
return err
5656
}
5757
dbList := sdk.Runtime.GetDb()

app/admin/models/sys_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type SysConfig struct {
1616
models.ModelTime
1717
}
1818

19-
func (SysConfig) TableName() string {
19+
func (*SysConfig) TableName() string {
2020
return "sys_config"
2121
}
2222

app/admin/models/sys_dept.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type SysDept struct {
77
ParentId int `json:"parentId" gorm:""` //上级部门
88
DeptPath string `json:"deptPath" gorm:"size:255;"` //
99
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
10-
Sort int `json:"sort" gorm:"size:4;"` //排序
10+
Sort int `json:"sort" gorm:"size:4;"` //排序
1111
Leader string `json:"leader" gorm:"size:128;"` //负责人
1212
Phone string `json:"phone" gorm:"size:11;"` //手机
1313
Email string `json:"email" gorm:"size:64;"` //邮箱
@@ -19,7 +19,7 @@ type SysDept struct {
1919
Children []SysDept `json:"children" gorm:"-"`
2020
}
2121

22-
func (SysDept) TableName() string {
22+
func (*SysDept) TableName() string {
2323
return "sys_dept"
2424
}
2525

app/admin/models/sys_dict_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type SysDictData struct {
2020
models.ModelTime
2121
}
2222

23-
func (SysDictData) TableName() string {
23+
func (*SysDictData) TableName() string {
2424
return "sys_dict_data"
2525
}
2626

app/admin/models/sys_dict_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type SysDictType struct {
1414
models.ModelTime
1515
}
1616

17-
func (SysDictType) TableName() string {
17+
func (*SysDictType) TableName() string {
1818
return "sys_dict_type"
1919
}
2020

app/admin/models/sys_login_log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type SysLoginLog struct {
2929
models.ControlBy
3030
}
3131

32-
func (SysLoginLog) TableName() string {
32+
func (*SysLoginLog) TableName() string {
3333
return "sys_login_log"
3434
}
3535

app/admin/models/sys_menu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (x SysMenuSlice) Len() int { return len(x) }
3636
func (x SysMenuSlice) Less(i, j int) bool { return x[i].Sort < x[j].Sort }
3737
func (x SysMenuSlice) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
3838

39-
func (SysMenu) TableName() string {
39+
func (*SysMenu) TableName() string {
4040
return "sys_menu"
4141
}
4242

app/admin/models/sys_opera_log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type SysOperaLog struct {
3737
models.ControlBy
3838
}
3939

40-
func (SysOperaLog) TableName() string {
40+
func (*SysOperaLog) TableName() string {
4141
return "sys_opera_log"
4242
}
4343

app/admin/models/sys_post.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type SysPost struct {
1616
Params string `gorm:"-" json:"params"`
1717
}
1818

19-
func (SysPost) TableName() string {
19+
func (*SysPost) TableName() string {
2020
return "sys_post"
2121
}
2222

@@ -27,4 +27,4 @@ func (e *SysPost) Generate() models.ActiveRecord {
2727

2828
func (e *SysPost) GetId() interface{} {
2929
return e.PostId
30-
}
30+
}

app/admin/models/sys_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type SysRole struct {
2121
models.ModelTime
2222
}
2323

24-
func (SysRole) TableName() string {
24+
func (*SysRole) TableName() string {
2525
return "sys_role"
2626
}
2727

app/admin/models/sys_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type SysUser struct {
2929
models.ModelTime
3030
}
3131

32-
func (SysUser) TableName() string {
32+
func (*SysUser) TableName() string {
3333
return "sys_user"
3434
}
3535

@@ -42,7 +42,7 @@ func (e *SysUser) GetId() interface{} {
4242
return e.UserId
4343
}
4444

45-
//加密
45+
// Encrypt 加密
4646
func (e *SysUser) Encrypt() (err error) {
4747
if e.Password == "" {
4848
return

app/admin/router/router.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var (
1212
routerCheckRole = make([]func(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware), 0)
1313
)
1414

15-
// 路由示例
1615
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
1716

1817
// 无需认证的路由
@@ -39,4 +38,4 @@ func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle
3938
for _, f := range routerCheckRole {
4039
f(v1, authMiddleware)
4140
}
42-
}
41+
}

app/admin/service/sys_dept.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (e *SysDept) deptPageCall(deptlist *[]models.SysDept, menu models.SysDept)
237237
return menu
238238
}
239239

240-
// GetRoleDeptId 获取角色的部门ID集合
240+
// GetWithRoleId 获取角色的部门ID集合
241241
func (e *SysDept) GetWithRoleId(roleId int) ([]int, error) {
242242
deptIds := make([]int, 0)
243243
deptList := make([]dto.DeptIdList, 0)

app/jobs/examples.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import (
55
"time"
66
)
77

8+
// InitJob
89
// 需要将定义的struct 添加到字典中;
910
// 字典 key 可以配置到 自动任务 调用目标 中;
1011
func InitJob() {
11-
jobList = map[string]JobsExec{
12+
jobList = map[string]JobExec{
1213
"ExamplesOne": ExamplesOne{},
1314
// ...
1415
}
1516
}
1617

18+
// ExamplesOne
1719
// 新添加的job 必须按照以下格式定义,并实现Exec函数
1820
type ExamplesOne struct {
1921
}

app/jobs/jobbase.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/go-admin-team/go-admin-core/sdk"
77
models2 "go-admin/app/jobs/models"
88
"gorm.io/gorm"
9-
"sync"
109
"time"
1110

1211
"github.com/robfig/cron/v3"
@@ -18,8 +17,9 @@ import (
1817
var timeFormat = "2006-01-02 15:04:05"
1918
var retryCount = 3
2019

21-
var jobList map[string]JobsExec
22-
var lock sync.Mutex
20+
var jobList map[string]JobExec
21+
22+
//var lock sync.Mutex
2323

2424
type JobCore struct {
2525
InvokeTarget string
@@ -30,7 +30,7 @@ type JobCore struct {
3030
Args string
3131
}
3232

33-
// 任务类型 http
33+
// HttpJob 任务类型 http
3434
type HttpJob struct {
3535
JobCore
3636
}
@@ -46,7 +46,7 @@ func (e *ExecJob) Run() {
4646
log.Warn("[Job] ExecJob Run job nil")
4747
return
4848
}
49-
err := CallExec(obj.(JobsExec), e.Args)
49+
err := CallExec(obj.(JobExec), e.Args)
5050
if err != nil {
5151
// 如果失败暂停一段时间重试
5252
fmt.Println(time.Now().Format(timeFormat), " [ERROR] mission failed! ", err)
@@ -63,7 +63,7 @@ func (e *ExecJob) Run() {
6363
return
6464
}
6565

66-
//http 任务接口
66+
// Run http 任务接口
6767
func (h *HttpJob) Run() {
6868

6969
startTime := time.Now()
@@ -95,7 +95,7 @@ LOOP:
9595
return
9696
}
9797

98-
// 初始化
98+
// Setup 初始化
9999
func Setup(dbs map[string]*gorm.DB) {
100100

101101
fmt.Println(time.Now().Format(timeFormat), " [INFO] JobCore Starting...")
@@ -152,7 +152,7 @@ func setup(key string, db *gorm.DB) {
152152
select {}
153153
}
154154

155-
// 添加任务 AddJob(invokeTarget string, jobId int, jobName string, cronExpression string)
155+
// AddJob 添加任务 AddJob(invokeTarget string, jobId int, jobName string, cronExpression string)
156156
func AddJob(c *cron.Cron, job Job) (int, error) {
157157
if job == nil {
158158
fmt.Println("unknown")
@@ -171,8 +171,8 @@ func (h *HttpJob) addJob(c *cron.Cron) (int, error) {
171171
return EntryId, nil
172172
}
173173

174-
func (h *ExecJob) addJob(c *cron.Cron) (int, error) {
175-
id, err := c.AddJob(h.CronExpression, h)
174+
func (e *ExecJob) addJob(c *cron.Cron) (int, error) {
175+
id, err := c.AddJob(e.CronExpression, e)
176176
if err != nil {
177177
fmt.Println(time.Now().Format(timeFormat), " [ERROR] JobCore AddJob error", err)
178178
return 0, err
@@ -181,7 +181,7 @@ func (h *ExecJob) addJob(c *cron.Cron) (int, error) {
181181
return EntryId, nil
182182
}
183183

184-
// 移除任务
184+
// Remove 移除任务
185185
func Remove(c *cron.Cron, entryID int) chan bool {
186186
ch := make(chan bool)
187187
go func() {

app/jobs/models/sys_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type SysJob struct {
2323
DataScope string `json:"dataScope" gorm:"-"`
2424
}
2525

26-
func (SysJob) TableName() string {
26+
func (*SysJob) TableName() string {
2727
return "sys_job"
2828
}
2929

@@ -48,7 +48,7 @@ func (e *SysJob) GetList(tx *gorm.DB, list interface{}) (err error) {
4848
return tx.Table(e.TableName()).Where("status = ?", 2).Find(list).Error
4949
}
5050

51-
// 更新SysJob
51+
// Update 更新SysJob
5252
func (e *SysJob) Update(tx *gorm.DB, id interface{}) (err error) {
5353
return tx.Table(e.TableName()).Where(id).Updates(&e).Error
5454
}

app/jobs/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ type Job interface {
77
addJob(*cron.Cron) (int, error)
88
}
99

10-
type JobsExec interface {
10+
type JobExec interface {
1111
Exec(arg interface{}) error
1212
}
1313

14-
func CallExec(e JobsExec, arg interface{}) error {
14+
func CallExec(e JobExec, arg interface{}) error {
1515
return e.Exec(arg)
1616
}

app/other/apis/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type File struct {
4444
func (e File) UploadFile(c *gin.Context) {
4545
e.MakeContext(c)
4646
tag, _ := c.GetPostForm("type")
47-
urlPrefix := fmt.Sprintf("http://%s/", c.Request.Host)
47+
urlPrefix := fmt.Sprintf("%s://%s/", "http", c.Request.Host)
4848
var fileResponse FileResponse
4949

5050
switch tag {
@@ -201,4 +201,4 @@ func ossUpload(name string, path string) error {
201201
func qiniuUpload(name string, path string) error {
202202
oss := file_store.ALiYunOSS{}
203203
return oss.UpLoad(name, path)
204-
}
204+
}

0 commit comments

Comments
 (0)