Skip to content

Commit

Permalink
chore: 更新lint版本并调整配置
Browse files Browse the repository at this point in the history
  • Loading branch information
SugarMGP authored Nov 19, 2024
1 parent 97b1599 commit 62044b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6 # 使用 golangci-lint-action
with:
version: v1.61.0 # 指定 golangci-lint 版本
version: v1.62.0 # 指定 golangci-lint 版本
args: '--config .golangci.yml' # 使用指定的配置文件
15 changes: 9 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@ linters-settings:
# 默认失败置信度
confidence: 0.1
rules:
- name: var-naming # 变量命名规则
- name: var-naming # 变量命名规则
severity: warning
disabled: true
- name: line-length-limit # 行长度限制
- name: line-length-limit # 行长度限制
severity: warning
disabled: false
exclude: [ "" ]
arguments: [ 120 ]
- name: add-constant #使用命名常量而非魔法数字
- name: add-constant # 使用命名常量而非魔法数字
severity: warning
disabled: true
- name: package-comments #包注释
- name: package-comments # 包注释
severity: warning
disabled: true
- name: import-alias-naming #导入别名命名规则
- name: import-alias-naming # 导入别名命名规则
severity: warning
disabled: true
- name: get-return #使用get必须有返回值
- name: get-return # 使用get必须有返回值
severity: warning
disabled: true
- name: max-public-structs # 最大公共结构体数目
severity: warning
disabled: true
- name: cognitive-complexity
Expand Down
6 changes: 3 additions & 3 deletions app/services/sessionService/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func UpdateUserSession(c *gin.Context) (*models.User, error) {
// GetUserSession 检查用户session缓存
func GetUserSession(c *gin.Context) (*models.User, error) {
webSession := sessions.Default(c)
id := webSession.Get("id")
if id == nil {
id, ok := webSession.Get("id").(uint)
if !ok {
return nil, errors.New("")
}
user, err := userService.GetUserByID(id.(uint))
user, err := userService.GetUserByID(id)
if err != nil {
if err := ClearUserSession(c); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ go run main.go
go run main.go
```
5. 每次提交commit前,先运行以下代码检查后端
使用[golangci-lint](https://golangci-lint.run/)(v1.16.0)检查代码(其他版本会有其他报错,先以这个版本为主)
使用[golangci-lint](https://golangci-lint.run/)(v1.62.0)检查代码
```
golangci-lint run --config .golangci.yml
```
Expand Down

0 comments on commit 62044b0

Please sign in to comment.