Skip to content

Commit 129cfcf

Browse files
committed
WIP lint
1 parent 84655fa commit 129cfcf

File tree

13 files changed

+56
-30
lines changed

13 files changed

+56
-30
lines changed

.golangci.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
version: "2"
2+
23
linters:
34
default: standard
45
disable:
5-
- errcheck
6+
- errcheck # Too many issues to fix incrementally (50+)
7+
enable:
8+
- gocyclo
9+
- misspell
10+
- gocritic
11+
- unconvert
12+
- unparam
13+
- revive
14+
settings:
15+
gocyclo:
16+
min-complexity: 80 # Start lenient, tighten later (default: 30)
17+
gocritic:
18+
disabled-checks:
19+
- ifElseChain # Stylistic preference, not a bug
20+
unparam:
21+
check-exported: false # Only check unexported functions
22+
revive:
23+
rules:
24+
- name: exported
25+
disabled: true # Too many missing comments
26+
- name: package-comments
27+
disabled: true # Too many missing package comments
28+
- name: var-naming
29+
disabled: true # Would require significant refactoring (ApiKey -> APIKey, etc)
630

internal/agent/m3/m3.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (m3 *M3App) RunSingle() error {
140140
return err
141141
}
142142

143-
if len(resp) <= 0 {
143+
if len(resp) == 0 {
144144
logger.Log("WARNING: skip empty resp")
145145
return err
146146
}
@@ -184,7 +184,7 @@ func GetM3FinEndpoint(timestamp string, timezone string, pids map[int]string) st
184184
/// append pod name and namespace in Kubernetes
185185
if config.GlobalConfig.Kubernetes {
186186
podName := getPodName()
187-
//parameters += "&pod=" + podName
187+
// parameters += "&pod=" + podName
188188
ns := getMatchingNamespace(podName)
189189
if ns != "" {
190190
// parameters += "&ns=" + ns
@@ -211,7 +211,8 @@ func GetM3CommonEndpointParameters(timestamp string, timezone string) string {
211211
return parameters
212212
}
213213

214-
func (m3 *M3App) captureAndTransmit(pids map[int]string, endpoint string) (err error) {
214+
//nolint:unparam // error return kept for future error handling
215+
func (m3 *M3App) captureAndTransmit(pids map[int]string, endpoint string) error {
215216
logger.Log("yc-360 script version: " + executils.SCRIPT_VERSION)
216217
logger.Log("yc-360 script starting in m3 mode...")
217218

@@ -264,7 +265,7 @@ Resp: %s
264265
--------------------------------
265266
`, lpM3Result.Ok, lpM3Result.Msg)
266267

267-
return
268+
return nil
268269
}
269270

270271
func uploadGCLogM3(endpoint string, pid int) string {
@@ -506,7 +507,7 @@ Resps: %s
506507

507508
func (m3 *M3App) uploadAccessLogM3(endpoint string, pid int, appName string) {
508509
var accessLogM3Chan chan capture.Result
509-
if len(config.GlobalConfig.AccessLogs) <= 0 {
510+
if len(config.GlobalConfig.AccessLogs) == 0 {
510511
return
511512
}
512513

internal/agent/m3/m3_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestProcessResp(t *testing.T) {
2323

2424
func TestM3FinPids(t *testing.T) {
2525
var a = func(pids []int) string {
26-
if len(pids) <= 0 {
26+
if len(pids) == 0 {
2727
return ""
2828
}
2929
var ps strings.Builder

internal/agent/ondemand/ondemand.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
var Wg sync.WaitGroup
3737

3838
func ProcessPids(pids []int, pid2Name map[int]string, hd bool, tags string, timestamps []string) (rUrls []string, err error) {
39-
if len(pids) <= 0 {
39+
if len(pids) == 0 {
4040
logger.Log("Empty pids, no action needed.")
4141
return
4242
}
@@ -103,7 +103,7 @@ func FullCapture(pid int, appName string, hd bool, tags string, tsParam string)
103103
if tsParam == "" {
104104
tsParam = timestamp
105105
}
106-
//parameters = fmt.Sprintf("de=%s&ts=%s", getOutboundIP().String(), tsParam)
106+
// parameters = fmt.Sprintf("de=%s&ts=%s", getOutboundIP().String(), tsParam)
107107
timezoneBase64 := base64.StdEncoding.EncodeToString([]byte(timezone))
108108
parameters = fmt.Sprintf("de=%s&ts=%s&timezoneId=%s", getOutboundIP().String(), tsParam, timezoneBase64)
109109
endpoint = fmt.Sprintf("%s/ycrash-receiver?%s", config.GlobalConfig.Server, parameters)
@@ -454,7 +454,7 @@ Falling back to capture all configured appLogs without appName filtering.`)
454454

455455
paths := config.AppLogs{}
456456
for _, f := range discoveredLogFiles {
457-
logger.Debug().Msgf("OnDemand FullCapture: discovered log file: %s", string(f))
457+
logger.Debug().Msgf("OnDemand FullCapture: discovered log file: %s", f)
458458
isGCLog := false
459459
for _, fileName := range globFiles {
460460
// To exclude discovered gc log such f as /tmp/buggyapp-%p-%t.log

internal/capture/access_log.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
const accessLogOut = "accesslog.out"
1111

1212
// AccessLog represents struct that captures and uploads the specified log file.
13+
//
1314
// Deprecated: use App logs auto discovery instead.
1415
type AccessLog struct {
1516
Capture

internal/capture/accesslogm3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (a *AccessLogM3) Run() (Result, error) {
7878
// %t = current date
7979
p := strings.ReplaceAll(string(path.Path), "%t", currentDateStr)
8080

81-
matches, err := zglob.Glob(string(p))
81+
matches, err := zglob.Glob(p)
8282

8383
if err != nil {
8484
results = append(results, Result{

internal/capture/app_logs_auto_discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func DiscoverOpenedLogFilesByProcess(pid int) ([]string, error) {
3535
}
3636

3737
for _, filePath := range openedFiles {
38-
logger.Debug().Msgf("DiscoverOpenedLogFilesByProcess: opened file by process (pid=%d): %s", pid, string(filePath))
38+
logger.Debug().Msgf("DiscoverOpenedLogFilesByProcess: opened file by process (pid=%d): %s", pid, filePath)
3939

4040
fileBaseName := filepath.Base(filePath)
4141
if matchLogPattern(fileBaseName) {

internal/capture/applog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (al *AppLog) Run() (Result, error) {
5252

5353
// Process each expanded file path
5454
for _, filePath := range expandedPaths {
55-
logger.Debug().Msgf("AppLog: expanded path: %s", string(filePath))
55+
logger.Debug().Msgf("AppLog: expanded path: %s", filePath)
5656

5757
r, err := al.CaptureSingleAppLog(filePath)
5858
results = append(results, r)

internal/capture/boomi.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type AtomConnector struct {
100100

101101
func CaptureBoomiDetails(endpoint string, timestamp string, pid int) {
102102
// get Boomi details from the config
103-
boomiURL := BoomiURL //config.GlobalConfig.BoomiUrl
103+
boomiURL := BoomiURL // config.GlobalConfig.BoomiUrl
104104
if boomiURL == "" {
105105
logger.Log("Boomi server URL is missing. It is mandatory.")
106106
return
@@ -204,7 +204,7 @@ func fetchBoomiExecutionRecords(boomiUserName, boomiPassword, boomiURL string) (
204204

205205
logger.Log("Length of Boomi queryResult.Result->%d", len(queryResult.Result))
206206

207-
if len(queryResult.Result) <= 0 {
207+
if len(queryResult.Result) == 0 {
208208
return records, nil
209209
}
210210

@@ -254,7 +254,7 @@ func fetchAtomConnectorDetails(boomiUserName, boomiPassword, boomiURL string) ([
254254
return records, fmt.Errorf("error unmarshalling Boomi response as JSON: %w", jsonErr)
255255
}
256256
logger.Log("Length of Boomi queryResult.Result->%d", len(queryResult.Result))
257-
if len(queryResult.Result) <= 0 {
257+
if len(queryResult.Result) == 0 {
258258
return records, nil
259259
}
260260

@@ -439,7 +439,7 @@ func (b *BoomiExecutionOutput) WriteAtomQueryDetails(atomQueryResult AtomQueryRe
439439
if err != nil {
440440
return fmt.Errorf("error while writing boomi execution output: %w", err)
441441
}
442-
//break
442+
// break
443443
} else {
444444
boomiData := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s,%d,%s,%s\n", atomQuery.Type, atomQuery.Name, atomQuery.Status, atomQuery.AtomType, atomQuery.HostName, atomQuery.DateInstalled, atomQuery.CurrentVersion, atomQuery.ForceRestartTime, atomQuery.ID, "N")
445445
_, err := b.file.WriteString(boomiData)
@@ -526,7 +526,7 @@ func makeBoomiRequest(queryToken string, username string, password string, boomi
526526
}
527527

528528
// Print the body content
529-
//fmt.Printf("Request Body: %s\n", string(bodyBytes))
529+
// fmt.Printf("Request Body: %s\n", string(bodyBytes))
530530

531531
// Reset the request body
532532
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
@@ -639,7 +639,7 @@ func makeAtomConnectorsRequest(queryToken string, username string, password stri
639639
}
640640

641641
// Print the body content
642-
//fmt.Printf("Request Body: %s\n", string(bodyBytes))
642+
// fmt.Printf("Request Body: %s\n", string(bodyBytes))
643643

644644
// Reset the request body
645645
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
@@ -722,7 +722,7 @@ func getAtomQueryDetails(accountID string, username string, password string) Ato
722722
return atomQueryResult
723723
}
724724

725-
//logger.Log("Atom Query details Result %v", atomQueryResult)
725+
// logger.Log("Atom Query details Result %v", atomQueryResult)
726726

727727
return atomQueryResult
728728
}

internal/capture/extended_data_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func setupMockServer(t *testing.T) *httptest.Server {
2323
}
2424

2525
// createTestScript creates a cross-platform test script
26-
func createTestScript(t *testing.T, outputFile string) (string, string) {
26+
func createTestScript(t *testing.T, outputFile string) string {
2727
scriptDir, err := os.MkdirTemp("", "extended-script-test-*")
2828
if err != nil {
2929
t.Fatalf("Failed to create temp dir: %v", err)
@@ -51,7 +51,7 @@ func createTestScript(t *testing.T, outputFile string) (string, string) {
5151
t.Fatalf("Failed to get absolute path of script: %v", err)
5252
}
5353

54-
return absScriptFile, scriptDir
54+
return absScriptFile
5555
}
5656

5757
// createLongRunningScript creates a script that runs for a specified duration
@@ -100,7 +100,7 @@ func TestExtendedData_Run_Success(t *testing.T) {
100100
outputFile := filepath.Join(testDir, "output.log")
101101

102102
// Step 3: Create test script
103-
absScriptFile, _ := createTestScript(t, outputFile)
103+
absScriptFile := createTestScript(t, outputFile)
104104

105105
// Step 4: Create the ExtendedData struct
106106
ed := &ExtendedData{
@@ -180,7 +180,7 @@ func TestExtendedData_Run_FolderDeleting(t *testing.T) {
180180
outputFile := filepath.Join(testDir, "output.log")
181181

182182
// Step 3: Create test script
183-
absScriptFile, _ := createTestScript(t, outputFile)
183+
absScriptFile := createTestScript(t, outputFile)
184184

185185
// Step 4: Create the ExtendedData struct
186186
ed := &ExtendedData{
@@ -215,7 +215,7 @@ func TestExtendedData_Run_ScriptFolderSameAsDataFolder(t *testing.T) {
215215
outputFile := filepath.Join(testDir, "output.log")
216216

217217
// Step 3: Create test script
218-
absScriptFile, _ := createTestScript(t, outputFile)
218+
absScriptFile := createTestScript(t, outputFile)
219219

220220
// Step 4: Create the ExtendedData struct
221221
ed := &ExtendedData{
@@ -241,7 +241,7 @@ func TestExtendedData_Run_EmptyDataFolder(t *testing.T) {
241241

242242
// Step 1: Create test script
243243
tempOutputFile := filepath.Join(os.TempDir(), "output.log")
244-
absScriptFile, _ := createTestScript(t, tempOutputFile)
244+
absScriptFile := createTestScript(t, tempOutputFile)
245245

246246
// Step 2: Create the ExtendedData struct
247247
ed := &ExtendedData{
@@ -297,7 +297,7 @@ func TestExtendedData_Run_RelativePath(t *testing.T) {
297297
outputFile := filepath.Join(testDir, "output.log")
298298

299299
// Step 2: Create test script
300-
absScriptFile, _ := createTestScript(t, outputFile)
300+
absScriptFile := createTestScript(t, outputFile)
301301

302302
// Step 3: Create the ExtendedData struct
303303
ed := &ExtendedData{

0 commit comments

Comments
 (0)