style: fix ci-lint

This commit is contained in:
zhuyasen 2025-04-10 17:13:37 +08:00
parent 6c4ce7e6f9
commit 65e013ee3e
11 changed files with 41 additions and 30 deletions

View File

@ -5,11 +5,11 @@ import "strings"
var defaultMaxSize = 1000
// SetMaxSize change the default maximum number of pages per page
func SetMaxSize(max int) {
if max < 10 {
max = 10
func SetMaxSize(maxValue int) {
if maxValue < 10 {
maxValue = 10
}
defaultMaxSize = max
defaultMaxSize = maxValue
}
// Page info

View File

@ -95,13 +95,13 @@ func handleExec(ctx context.Context, cmd *exec.Cmd, result *Result) {
}
}
func getCmdReader(cmd *exec.Cmd) (io.ReadCloser, io.ReadCloser, error) {
stdout, err := cmd.StdoutPipe()
func getCmdReader(cmd *exec.Cmd) (stdout io.ReadCloser, stderr io.ReadCloser, err error) {
stdout, err = cmd.StdoutPipe()
if err != nil {
return nil, nil, err
}
stderr, err := cmd.StderrPipe()
stderr, err = cmd.StderrPipe()
if err != nil {
return nil, nil, err
}

View File

@ -76,6 +76,17 @@ func GetFilenameWithoutSuffix(filePath string) string {
return strings.TrimSuffix(name, path.Ext(name))
}
// GetRelativeFilePath get relative file path, force to use "/" as separator
func GetRelativeFilePath(absFilePath string) string {
dirPath, _ := filepath.Abs(".")
dirPath = filepath.ToSlash(filepath.Clean(dirPath))
absFilePath = filepath.ToSlash(filepath.Clean(absFilePath))
if !strings.HasSuffix(dirPath, "/") {
dirPath += "/"
}
return strings.TrimPrefix(absFilePath, dirPath)
}
// Join joins any number of path elements into a single path
func Join(elem ...string) string {
dir := strings.Join(elem, "/")

View File

@ -105,6 +105,9 @@ func TestGetFilename(t *testing.T) {
name = GetFilenameWithoutSuffix("./README.md")
assert.Equal(t, "README", name)
fp := GetRelativeFilePath("/user/sponge/pkg/gofile/testDir/test.txt")
assert.Contains(t, fp, "testDir/test.txt")
}
func TestGetPathDelimiter(t *testing.T) {

View File

@ -25,7 +25,7 @@ type circuitBreakerOptions struct {
validCodes map[codes.Code]struct{}
// degrade handler for unary server
unaryServerDegradeHandler func(ctx context.Context, req interface{}) (reply interface{}, error error)
unaryServerDegradeHandler func(ctx context.Context, req interface{}) (reply interface{}, err error)
}
func defaultCircuitBreakerOptions() *circuitBreakerOptions {
@ -66,7 +66,7 @@ func WithValidCode(code ...codes.Code) CircuitBreakerOption {
}
// WithUnaryServerDegradeHandler unary server degrade handler function
func WithUnaryServerDegradeHandler(handler func(ctx context.Context, req interface{}) (reply interface{}, error error)) CircuitBreakerOption {
func WithUnaryServerDegradeHandler(handler func(ctx context.Context, req interface{}) (reply interface{}, err error)) CircuitBreakerOption {
return func(o *circuitBreakerOptions) {
o.unaryServerDegradeHandler = handler
}

View File

@ -11,11 +11,11 @@ var defaultMaxSize = 1000
const oidName = "_id"
// SetMaxSize change the default maximum number of pages per page
func SetMaxSize(max int) {
if max < 10 {
max = 10
func SetMaxSize(maxValue int) {
if maxValue < 10 {
maxValue = 10
}
defaultMaxSize = max
defaultMaxSize = maxValue
}
// Page info

View File

@ -5,11 +5,11 @@ import "strings"
var defaultMaxSize = 1000
// SetMaxSize change the default maximum number of pages per page
func SetMaxSize(max int) {
if max < 10 {
max = 10
func SetMaxSize(maxValue int) {
if maxValue < 10 {
maxValue = 10
}
defaultMaxSize = max
defaultMaxSize = maxValue
}
// Page info

View File

@ -45,8 +45,8 @@ var currentDriver string
// SetDriver sets the name of the current database driver, such as "postgres"
// if you use postgres, you need to call SetDriver("postgres") after initializing gorm
func SetDriver(driver string) {
currentDriver = driver
func SetDriver(driverName string) {
currentDriver = driverName
}
// --------------------------------------------------------------------------------------

View File

@ -63,19 +63,19 @@ func ParseUintList(val string) (map[int]bool, error) {
}
availableInts[v] = true
} else {
split := strings.SplitN(r, "-", 2)
min, err := strconv.Atoi(split[0])
ss := strings.SplitN(r, "-", 2)
minVal, err := strconv.Atoi(ss[0])
if err != nil {
return nil, errInvalidFormat
}
max, err := strconv.Atoi(split[1])
maxVal, err := strconv.Atoi(ss[1])
if err != nil {
return nil, errInvalidFormat
}
if max < min {
if maxVal < minVal {
return nil, errInvalidFormat
}
for i := min; i <= max; i++ {
for i := minVal; i <= maxVal; i++ {
availableInts[i] = true
}
}

View File

@ -43,14 +43,14 @@ func cpuproc() {
for range ticker.C {
stat := &cpu.Stat{}
cpu.ReadStat(stat)
stat.Usage = min(stat.Usage, 1000)
stat.Usage = getMin(stat.Usage, 1000)
prevCPU := atomic.LoadInt64(&gCPU)
curCPU := int64(float64(prevCPU)*decay + float64(stat.Usage)*(1.0-decay))
atomic.StoreInt64(&gCPU, curCPU)
}
}
func min(l, r uint64) uint64 {
func getMin(l, r uint64) uint64 {
if l < r {
return l
}

View File

@ -48,8 +48,8 @@ func (p *WaitPrinter) LoopPrint(runningTip string) {
index++
if index >= len(symbols) {
index = 0
p.clearCurrentLine()
}
p.clearCurrentLine()
fmt.Printf("\r%s", symbols[index])
}
}
@ -70,9 +70,6 @@ func (p *WaitPrinter) StopPrint(tip string) {
p.cancel()
p.clearCurrentLine()
if tip == "" {
return
}
fmt.Println(tip)
}