style: adjustment code

This commit is contained in:
zhuyasen
2024-12-01 15:13:22 +08:00
parent 967013cc51
commit fdb83e6fd1
7 changed files with 17 additions and 15 deletions

1
.gitignore vendored
View File

@@ -3,7 +3,6 @@
*.exe~ *.exe~
*.dll *.dll
*.so *.so
*.dylib
*.log *.log
# Test binary, built with `go test -c` # Test binary, built with `go test -c`

View File

@@ -56,7 +56,7 @@ linters:
- unconvert - unconvert
- whitespace - whitespace
- staticcheck - staticcheck
#- bodyclose - bodyclose
#- dupl #- dupl
#- goprintffuncname #- goprintffuncname
#- gosec #- gosec
@@ -67,6 +67,8 @@ linters:
linters-settings: linters-settings:
revive: revive:
rules: rules:
- name: indent-error-flow
- name: unused-parameter
- name: argument-limit - name: argument-limit
arguments: [ 8 ] arguments: [ 8 ]
- name: atomic - name: atomic
@@ -96,7 +98,6 @@ linters-settings:
- name: if-return - name: if-return
- name: import-shadowing - name: import-shadowing
- name: increment-decrement - name: increment-decrement
- name: indent-error-flow
- name: modifies-parameter - name: modifies-parameter
- name: modifies-value-receiver - name: modifies-value-receiver
- name: package-comments - name: package-comments
@@ -113,7 +114,6 @@ linters-settings:
- name: unexported-naming - name: unexported-naming
- name: unnecessary-stmt - name: unnecessary-stmt
- name: unreachable-code - name: unreachable-code
- name: unused-parameter
- name: var-declaration - name: var-declaration
- name: var-naming - name: var-naming
- name: waitgroup-by-value - name: waitgroup-by-value

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 zhuyasen Copyright (c) 2022 zhufuyi
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -6,6 +6,7 @@ package merge
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"errors"
"fmt" "fmt"
"os" "os"
"path" "path"
@@ -112,7 +113,7 @@ func (m *mergeParam) runMergeCode(file string) (string, error) {
count1 := bytes.Count(data1, m.splitLineMark) count1 := bytes.Count(data1, m.splitLineMark)
count2 := bytes.Count(data2, m.splitLineMark) count2 := bytes.Count(data2, m.splitLineMark)
if count1 != count2 { if count1 != count2 {
return "", fmt.Errorf(color.RedString("merge code failed (%s --> %s), manually merge code"+ return "", errors.New(color.RedString("merge code failed (%s --> %s), manually merge code"+
" reference document https://github.com/zhufuyi/sponge/tree/main/cmd/sponge/commands/merge", " reference document https://github.com/zhufuyi/sponge/tree/main/cmd/sponge/commands/merge",
cutPathPrefix(file), getTargetFilename(file))) cutPathPrefix(file), getTargetFilename(file)))
} }
@@ -135,7 +136,7 @@ func (m *mergeParam) runMergeCode(file string) (string, error) {
} }
if len(data1) > len(data) { if len(data1) > len(data) {
return "", fmt.Errorf(color.RedString("merge code failed (%s --> %s), to avoid replacing logical code, "+ return "", errors.New(color.RedString("merge code failed (%s --> %s), to avoid replacing logical code, "+
"manually merge code reference document https://github.com/zhufuyi/sponge/tree/main/cmd/sponge/commands/merge", "manually merge code reference document https://github.com/zhufuyi/sponge/tree/main/cmd/sponge/commands/merge",
cutPathPrefix(file), getTargetFilename(file))) cutPathPrefix(file), getTargetFilename(file)))
} }

View File

@@ -13,12 +13,12 @@ type Group struct {
} }
// NewGroup news a group container. // NewGroup news a group container.
func NewGroup(new func() interface{}) *Group { func NewGroup(fn func() interface{}) *Group {
if new == nil { if fn == nil {
panic("container.group: can't assign a nil to the new function") panic("container.group: can't assign a nil to the new function")
} }
return &Group{ return &Group{
new: new, new: fn,
vals: make(map[string]interface{}), vals: make(map[string]interface{}),
} }
} }
@@ -46,12 +46,12 @@ func (g *Group) Get(key string) interface{} {
} }
// Reset resets the new function and deletes all existing objects. // Reset resets the new function and deletes all existing objects.
func (g *Group) Reset(new func() interface{}) { func (g *Group) Reset(fn func() interface{}) {
if new == nil { if fn == nil {
panic("container.group: can't assign a nil to the new function") panic("container.group: can't assign a nil to the new function")
} }
g.Lock() g.Lock()
g.new = new g.new = fn
g.Unlock() g.Unlock()
g.Clear() g.Clear()
} }

View File

@@ -116,7 +116,7 @@ func getSQL(args *Args) (string, map[string]string, error) {
sqlStr, mongoTypeMap := parser.ConvertToSQLByMgoFields(args.DBTable, fields) sqlStr, mongoTypeMap := parser.ConvertToSQLByMgoFields(args.DBTable, fields)
return sqlStr, mongoTypeMap, nil return sqlStr, mongoTypeMap, nil
default: default:
return "", nil, fmt.Errorf("getsql error, unsupported database driver: " + dbDriverName) return "", nil, errors.New("get sql error, unsupported database driver: " + dbDriverName)
} }
} }

View File

@@ -63,7 +63,9 @@ func (p *WaitPrinter) StopPrint(tip string) {
} }
defer func() { defer func() {
recover() if e := recover(); e != nil {
fmt.Println(e)
}
}() }()
p.cancel() p.cancel()