mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-21 10:27:14 +00:00
style: adopt golangci-lint v2 and resolve all findings
Add .golangci.yml (v2): the standard linters plus bodyclose, errorlint, noctx, misspell, rowserrcheck, sqlclosecheck, unconvert, usestdlibvars, with gofumpt + goimports formatters. Enable the std-error-handling exclusion preset for idiomatic Close/Remove/Setenv ignores; scope-exclude SA1019 (parser.ParseDir in tools/openapigen) and ST1005 (intentional capitalized user-facing error copy that tests assert verbatim). No inline nolint directives were introduced. Resolve all 217 findings behavior-preserving: gofumpt/goimports formatting, explicit blank assignment on intentionally ignored errors, errors.Is/errors.As and %w wrapping, context-aware stdlib calls (CommandContext/QueryContext/NewRequestWithContext/Dialer), staticcheck simplifications, removed redundant conversions, http.StatusOK and http.MethodGet, inlined the go:fix intPtr helper, and deferred sql rows Close. Add a golangci CI job mirroring the existing Go jobs.
This commit is contained in:
@@ -2,6 +2,7 @@ package xray
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -74,7 +75,7 @@ func GetAccessLogPath() (string, error) {
|
||||
}
|
||||
|
||||
jsonConfig := map[string]any{}
|
||||
err = json.Unmarshal([]byte(config), &jsonConfig)
|
||||
err = json.Unmarshal(config, &jsonConfig)
|
||||
if err != nil {
|
||||
logger.Warningf("Failed to parse JSON configuration: %s", err)
|
||||
return "", err
|
||||
@@ -92,7 +93,7 @@ func GetAccessLogPath() (string, error) {
|
||||
|
||||
// stopProcess calls Stop on the given Process instance.
|
||||
func stopProcess(p *Process) {
|
||||
p.Stop()
|
||||
_ = p.Stop()
|
||||
}
|
||||
|
||||
// Process wraps an Xray process instance and provides management methods.
|
||||
@@ -475,7 +476,7 @@ func (p *process) refreshAPIPort() {
|
||||
|
||||
// refreshVersion updates the version string by running the Xray binary with -version.
|
||||
func (p *process) refreshVersion() {
|
||||
cmd := exec.Command(GetBinaryPath(), "-version")
|
||||
cmd := exec.CommandContext(context.Background(), GetBinaryPath(), "-version")
|
||||
data, err := cmd.Output()
|
||||
if err != nil {
|
||||
p.version = "Unknown"
|
||||
@@ -521,7 +522,7 @@ func (p *process) Start() (err error) {
|
||||
return common.NewErrorf("Failed to write configuration file: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(GetBinaryPath(), "-c", configPath)
|
||||
cmd := exec.CommandContext(context.Background(), GetBinaryPath(), "-c", configPath)
|
||||
cmd.Stdout = p.logWriter
|
||||
cmd.Stderr = p.logWriter
|
||||
|
||||
|
||||
@@ -12,8 +12,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
xuilogger "github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||
"github.com/op/go-logging"
|
||||
|
||||
xuilogger "github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||
)
|
||||
|
||||
func TestWriteFileAtomicModeAndRenameFailure(t *testing.T) {
|
||||
@@ -203,7 +204,7 @@ func markProcessHelperReady(t *testing.T) {
|
||||
if readyPath == "" {
|
||||
t.Fatal("XRAY_PROCESS_READY is not set")
|
||||
}
|
||||
if err := os.WriteFile(readyPath, []byte("ready"), 0644); err != nil {
|
||||
if err := os.WriteFile(readyPath, []byte("ready"), 0o644); err != nil {
|
||||
t.Fatalf("write helper ready file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -36,7 +37,7 @@ func ensureKillOnExitJob() (windows.Handle, error) {
|
||||
uint32(unsafe.Sizeof(info)),
|
||||
)
|
||||
if err != nil {
|
||||
windows.CloseHandle(h)
|
||||
_ = windows.CloseHandle(h)
|
||||
killOnExitJobErr = err
|
||||
return
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func attachChildLifetime(cmd *exec.Cmd) {
|
||||
logger.Warning("xray: OpenProcess for job attach failed:", err)
|
||||
return
|
||||
}
|
||||
defer windows.CloseHandle(h)
|
||||
defer func() { _ = windows.CloseHandle(h) }()
|
||||
if err := windows.AssignProcessToJobObject(job, h); err != nil {
|
||||
logger.Warning("xray: AssignProcessToJobObject failed:", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user