fix: Linter errors

Fixed:
- "ineffective break statement. Did you mean to break out of the outer loop?" (SA4011)
- "channels used with os/signal.Notify should be buffered" (SA1017)
- "os.Kill cannot be trapped (did you mean syscall.SIGTERM?)" (SA1016)
- "func envOrDefaultBool is unused" (U1000)
- "should use time.Since instead of time.Now().Sub" (S1012)
This commit is contained in:
macie 2024-03-11 22:15:57 +01:00
parent d98136bac7
commit 3022bde81b
No known key found for this signature in database
3 changed files with 6 additions and 15 deletions

View File

@ -208,10 +208,10 @@ func (s *socksStream) parseSocks5ReqMethod() utils.LSMAction {
switch method { switch method {
case Socks5AuthNotRequired: case Socks5AuthNotRequired:
s.authReqMethod = Socks5AuthNotRequired s.authReqMethod = Socks5AuthNotRequired
break return utils.LSMActionNext
case Socks5AuthPassword: case Socks5AuthPassword:
s.authReqMethod = Socks5AuthPassword s.authReqMethod = Socks5AuthPassword
break return utils.LSMActionNext
default: default:
// TODO: more auth method to support // TODO: more auth method to support
} }

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"strconv"
"strings" "strings"
"syscall" "syscall"
@ -278,15 +277,15 @@ func runMain(cmd *cobra.Command, args []string) {
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
go func() { go func() {
// Graceful shutdown // Graceful shutdown
shutdownChan := make(chan os.Signal) shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, os.Interrupt, os.Kill) signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
<-shutdownChan <-shutdownChan
logger.Info("shutting down gracefully...") logger.Info("shutting down gracefully...")
cancelFunc() cancelFunc()
}() }()
go func() { go func() {
// Rule reload // Rule reload
reloadChan := make(chan os.Signal) reloadChan := make(chan os.Signal, 1)
signal.Notify(reloadChan, syscall.SIGHUP) signal.Notify(reloadChan, syscall.SIGHUP)
for { for {
<-reloadChan <-reloadChan
@ -431,11 +430,3 @@ func envOrDefaultString(key, def string) string {
} }
return def return def
} }
func envOrDefaultBool(key string, def bool) bool {
if v := os.Getenv(key); v != "" {
b, _ := strconv.ParseBool(v)
return b
}
return def
}

View File

@ -49,7 +49,7 @@ func (l *V2GeoLoader) shouldDownload(filename string) bool {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return true return true
} }
dt := time.Now().Sub(info.ModTime()) dt := time.Since(info.ModTime())
if l.UpdateInterval == 0 { if l.UpdateInterval == 0 {
return dt > geoDefaultUpdateInterval return dt > geoDefaultUpdateInterval
} else { } else {