Skip to content

Commit

Permalink
perf👌: Optimize go warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjianzhang committed Aug 1, 2023
1 parent 69df1b3 commit 37a5963
Show file tree
Hide file tree
Showing 41 changed files with 83 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ Describe changes from the user side, and list all potential break changes or oth

- [ ] Doc is updated/provided or not needed
- [ ] Demo is updated/provided or not needed
- [ ] TypeScript definition is updated/provided or not needed
- [ ] TypeScript's definition is updated/provided or not needed
- [ ] Changelog is provided or not needed
4 changes: 2 additions & 2 deletions .github/workflows/issue-labeled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
token: ${{ secrets.ADMIN_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
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.
你好 @${{ 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` 标签哦~)。
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.
你好 @${{ 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` 标签哦~)。
- name: 3.x
if: github.event.label.name == '3.x'
uses: actions-cool/issues-helper@v3
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ config/settings.dev.yml.log
config/settings.b.dev.yml
cmd/migrate/migration/version-local/*
!cmd/migrate/migration/version-local/doc.go
*/.DS_Store

# go sum
go.sum
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ vi ./config/settings.yml
# 2. Confirm the log path
```

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

```bash
E:\go-admin>go build
Expand Down
2 changes: 1 addition & 1 deletion app/admin/apis/go_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ body{
overflow-y:hidden
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="https://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
window.onerror=function(){return true;}
$(function(){
Expand Down
1 change: 0 additions & 1 deletion app/admin/models/casbin_rule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package models

//sys_casbin_rule
type CasbinRule struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Ptype string `gorm:"size:512;uniqueIndex:unique_index"`
Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExecSql(db *gorm.DB, filePath string) error {
fmt.Println(sqlList[i])
continue
}
sql := strings.Replace(sqlList[i]+";", "\n", "", 0)
sql := strings.Replace(sqlList[i]+";", "\n", "", -1)
sql = strings.TrimSpace(sql)
if err = db.Exec(sql).Error; err != nil {
log.Printf("error sql: %s", sql)
Expand Down
6 changes: 3 additions & 3 deletions app/admin/models/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type SysApi struct {
models.ControlBy
}

func (SysApi) TableName() string {
func (*SysApi) TableName() string {
return "sys_api"
}

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

var l runtime.Routers
err = json.Unmarshal(rb, &l)
if err != nil {
fmt.Errorf("json Unmarshal error, %s", err.Error())
err = fmt.Errorf("json Unmarshal error, %s", err.Error())
return err
}
dbList := sdk.Runtime.GetDb()
Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SysConfig struct {
models.ModelTime
}

func (SysConfig) TableName() string {
func (*SysConfig) TableName() string {
return "sys_config"
}

Expand Down
4 changes: 2 additions & 2 deletions app/admin/models/sys_dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type SysDept struct {
ParentId int `json:"parentId" gorm:""` //上级部门
DeptPath string `json:"deptPath" gorm:"size:255;"` //
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
Sort int `json:"sort" gorm:"size:4;"` //排序
Sort int `json:"sort" gorm:"size:4;"` //排序
Leader string `json:"leader" gorm:"size:128;"` //负责人
Phone string `json:"phone" gorm:"size:11;"` //手机
Email string `json:"email" gorm:"size:64;"` //邮箱
Expand All @@ -19,7 +19,7 @@ type SysDept struct {
Children []SysDept `json:"children" gorm:"-"`
}

func (SysDept) TableName() string {
func (*SysDept) TableName() string {
return "sys_dept"
}

Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_dict_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SysDictData struct {
models.ModelTime
}

func (SysDictData) TableName() string {
func (*SysDictData) TableName() string {
return "sys_dict_data"
}

Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type SysDictType struct {
models.ModelTime
}

func (SysDictType) TableName() string {
func (*SysDictType) TableName() string {
return "sys_dict_type"
}

Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_login_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SysLoginLog struct {
models.ControlBy
}

func (SysLoginLog) TableName() string {
func (*SysLoginLog) TableName() string {
return "sys_login_log"
}

Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (x SysMenuSlice) Len() int { return len(x) }
func (x SysMenuSlice) Less(i, j int) bool { return x[i].Sort < x[j].Sort }
func (x SysMenuSlice) Swap(i, j int) { x[i], x[j] = x[j], x[i] }

func (SysMenu) TableName() string {
func (*SysMenu) TableName() string {
return "sys_menu"
}

Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/sys_opera_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type SysOperaLog struct {
models.ControlBy
}

func (SysOperaLog) TableName() string {
func (*SysOperaLog) TableName() string {
return "sys_opera_log"
}

Expand Down
4 changes: 2 additions & 2 deletions app/admin/models/sys_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SysPost struct {
Params string `gorm:"-" json:"params"`
}

func (SysPost) TableName() string {
func (*SysPost) TableName() string {
return "sys_post"
}

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

func (e *SysPost) GetId() interface{} {
return e.PostId
}
}
2 changes: 1 addition & 1 deletion app/admin/models/sys_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SysRole struct {
models.ModelTime
}

func (SysRole) TableName() string {
func (*SysRole) TableName() string {
return "sys_role"
}

Expand Down
4 changes: 2 additions & 2 deletions app/admin/models/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SysUser struct {
models.ModelTime
}

func (SysUser) TableName() string {
func (*SysUser) TableName() string {
return "sys_user"
}

Expand All @@ -42,7 +42,7 @@ func (e *SysUser) GetId() interface{} {
return e.UserId
}

//加密
// Encrypt 加密
func (e *SysUser) Encrypt() (err error) {
if e.Password == "" {
return
Expand Down
3 changes: 1 addition & 2 deletions app/admin/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var (
routerCheckRole = make([]func(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware), 0)
)

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

// 无需认证的路由
Expand All @@ -39,4 +38,4 @@ func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle
for _, f := range routerCheckRole {
f(v1, authMiddleware)
}
}
}
2 changes: 1 addition & 1 deletion app/admin/service/sys_dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (e *SysDept) deptPageCall(deptlist *[]models.SysDept, menu models.SysDept)
return menu
}

// GetRoleDeptId 获取角色的部门ID集合
// GetWithRoleId 获取角色的部门ID集合
func (e *SysDept) GetWithRoleId(roleId int) ([]int, error) {
deptIds := make([]int, 0)
deptList := make([]dto.DeptIdList, 0)
Expand Down
4 changes: 3 additions & 1 deletion app/jobs/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"time"
)

// InitJob
// 需要将定义的struct 添加到字典中;
// 字典 key 可以配置到 自动任务 调用目标 中;
func InitJob() {
jobList = map[string]JobsExec{
jobList = map[string]JobExec{
"ExamplesOne": ExamplesOne{},
// ...
}
}

// ExamplesOne
// 新添加的job 必须按照以下格式定义,并实现Exec函数
type ExamplesOne struct {
}
Expand Down
22 changes: 11 additions & 11 deletions app/jobs/jobbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/go-admin-team/go-admin-core/sdk"
models2 "go-admin/app/jobs/models"
"gorm.io/gorm"
"sync"
"time"

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

var jobList map[string]JobsExec
var lock sync.Mutex
var jobList map[string]JobExec

//var lock sync.Mutex

type JobCore struct {
InvokeTarget string
Expand All @@ -30,7 +30,7 @@ type JobCore struct {
Args string
}

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

//http 任务接口
// Run http 任务接口
func (h *HttpJob) Run() {

startTime := time.Now()
Expand Down Expand Up @@ -95,7 +95,7 @@ LOOP:
return
}

// 初始化
// Setup 初始化
func Setup(dbs map[string]*gorm.DB) {

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

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

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

// 移除任务
// Remove 移除任务
func Remove(c *cron.Cron, entryID int) chan bool {
ch := make(chan bool)
go func() {
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/models/sys_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SysJob struct {
DataScope string `json:"dataScope" gorm:"-"`
}

func (SysJob) TableName() string {
func (*SysJob) TableName() string {
return "sys_job"
}

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

// 更新SysJob
// Update 更新SysJob
func (e *SysJob) Update(tx *gorm.DB, id interface{}) (err error) {
return tx.Table(e.TableName()).Where(id).Updates(&e).Error
}
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type Job interface {
addJob(*cron.Cron) (int, error)
}

type JobsExec interface {
type JobExec interface {
Exec(arg interface{}) error
}

func CallExec(e JobsExec, arg interface{}) error {
func CallExec(e JobExec, arg interface{}) error {
return e.Exec(arg)
}
4 changes: 2 additions & 2 deletions app/other/apis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type File struct {
func (e File) UploadFile(c *gin.Context) {
e.MakeContext(c)
tag, _ := c.GetPostForm("type")
urlPrefix := fmt.Sprintf("http://%s/", c.Request.Host)
urlPrefix := fmt.Sprintf("%s://%s/", "http", c.Request.Host)
var fileResponse FileResponse

switch tag {
Expand Down Expand Up @@ -201,4 +201,4 @@ func ossUpload(name string, path string) error {
func qiniuUpload(name string, path string) error {
oss := file_store.ALiYunOSS{}
return oss.UpLoad(name, path)
}
}
Loading

0 comments on commit 37a5963

Please sign in to comment.