Skip to content

Commit 791dace

Browse files
committed
Apply for lints
1 parent 3c0a047 commit 791dace

File tree

8 files changed

+46
-60
lines changed

8 files changed

+46
-60
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ linters:
1111
- unconvert
1212
- unparam
1313
- revive
14+
- dogsled # Check for too many blank identifiers
15+
- bodyclose # Check HTTP response body is closed
16+
- whitespace # Check for unnecessary whitespace
17+
- wastedassign # Check for wasted assignments
1418
settings:
1519
gocyclo:
1620
min-complexity: 80 # Start lenient, tighten later (default: 30)

internal/agent/api/server_test.go

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ func TestServer(t *testing.T) {
4242
testErrCh <- err
4343
return
4444
}
45+
defer resp.Body.Close()
4546

46-
if resp.Body != nil {
47-
all, err := io.ReadAll(resp.Body)
48-
if err != nil {
49-
testErrCh <- err
50-
return
51-
}
52-
all = bytes.TrimSpace(all)
53-
if string(all) != `{"Code":0,"Msg":""}` {
54-
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
55-
return
56-
}
47+
all, err := io.ReadAll(resp.Body)
48+
if err != nil {
49+
testErrCh <- err
50+
return
51+
}
52+
all = bytes.TrimSpace(all)
53+
if string(all) != `{"Code":0,"Msg":""}` {
54+
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
55+
return
5756
}
5857
testErrCh <- nil
5958
}()
@@ -101,18 +100,17 @@ func TestServerCmdActions(t *testing.T) {
101100
testErrCh <- err
102101
return
103102
}
103+
defer resp.Body.Close()
104104

105-
if resp.Body != nil {
106-
all, err := io.ReadAll(resp.Body)
107-
if err != nil {
108-
testErrCh <- err
109-
return
110-
}
111-
all = bytes.TrimSpace(all)
112-
if !bytes.HasPrefix(all, []byte(`{"Code":0`)) {
113-
testErrCh <- fmt.Errorf("unexpected response: %s, %x", string(all), all)
114-
return
115-
}
105+
all, err := io.ReadAll(resp.Body)
106+
if err != nil {
107+
testErrCh <- err
108+
return
109+
}
110+
all = bytes.TrimSpace(all)
111+
if !bytes.HasPrefix(all, []byte(`{"Code":0`)) {
112+
testErrCh <- fmt.Errorf("unexpected response: %s, %x", string(all), all)
113+
return
116114
}
117115
testErrCh <- nil
118116
}()
@@ -183,18 +181,17 @@ func TestServerForward(t *testing.T) {
183181
testErrCh <- err
184182
return
185183
}
184+
defer resp.Body.Close()
186185

187-
if resp.Body != nil {
188-
all, err := io.ReadAll(resp.Body)
189-
if err != nil {
190-
testErrCh <- err
191-
return
192-
}
193-
all = bytes.TrimSpace(all)
194-
if string(all) != `{"Code":0,"Msg":""}` {
195-
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
196-
return
197-
}
186+
all, err := io.ReadAll(resp.Body)
187+
if err != nil {
188+
testErrCh <- err
189+
return
190+
}
191+
all = bytes.TrimSpace(all)
192+
if string(all) != `{"Code":0,"Msg":""}` {
193+
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
194+
return
198195
}
199196
testErrCh <- nil
200197
}()
@@ -247,18 +244,17 @@ func TestAttendanceAPI(t *testing.T) {
247244
testErrCh <- err
248245
return
249246
}
247+
defer resp.Body.Close()
250248

251-
if resp.Body != nil {
252-
all, err := io.ReadAll(resp.Body)
253-
if err != nil {
254-
testErrCh <- err
255-
return
256-
}
257-
all = bytes.TrimSpace(all)
258-
if string(all) != `{"Code":0,"Msg":""}` {
259-
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
260-
return
261-
}
249+
all, err := io.ReadAll(resp.Body)
250+
if err != nil {
251+
testErrCh <- err
252+
return
253+
}
254+
all = bytes.TrimSpace(all)
255+
if string(all) != `{"Code":0,"Msg":""}` {
256+
testErrCh <- fmt.Errorf("unexpected response: %s", string(all))
257+
return
262258
}
263259
testErrCh <- nil
264260
}()

internal/agent/ondemand/ondemand.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ func FullCapture(pid int, appName string, hd bool, tags string, tsParam string)
179179
// A.3 Agent log file
180180
var agentLogFile *os.File
181181
if !config.GlobalConfig.M3 {
182-
183182
// Renaming the log file name to yc360Logs from agentlog
184183
agentLogFile, err = logger.StartWritingToFile("yc360Logs.out")
185184
if err != nil {
@@ -376,7 +375,6 @@ Ignored errors: %v
376375
// ------------------------------------------------------------------------------
377376
var appLogs chan capture.Result
378377
if len(config.GlobalConfig.AppLogs) > 0 && config.GlobalConfig.AppLogLineCount != 0 {
379-
380378
appLogsContainDollarSign := false
381379
for _, configAppLog := range config.GlobalConfig.AppLogs {
382380
if strings.Contains(string(configAppLog), "$") {
@@ -417,7 +415,6 @@ Falling back to capture all configured appLogs without appName filtering.`)
417415
if found {
418416
appLogsMatchingAppName = append(appLogsMatchingAppName, config.AppLog(beforeSearchToken))
419417
}
420-
421418
}
422419

423420
if len(appLogsMatchingAppName) > 0 {
@@ -778,7 +775,6 @@ Resp: %s
778775
resp, err := RequestFin(finEp)
779776
if err != nil {
780777
logger.Log("post yc-fin err %s", err.Error())
781-
err = nil
782778
}
783779

784780
endTime := time.Now()

internal/agent/ondemand/ondemand_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func TestFindGCLog(t *testing.T) {
8888
if f != "garbage-collection.log" {
8989
t.Fatal("gc log file should be garbage-collection.log")
9090
}
91-
9291
}
9392

9493
func TestPostData(t *testing.T) {

internal/capture/applogm3_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestAppLogM3_CaptureSingleAppLog_ReadNewContent(t *testing.T) {
8888
require.NoError(t, err)
8989

9090
// Second call should copy only the appended content.
91-
res, err = appLog.CaptureSingleAppLog(filename, 123)
91+
_, err = appLog.CaptureSingleAppLog(filename, 123)
9292
require.NoError(t, err)
9393

9494
// Find the new destination file created.
@@ -147,7 +147,7 @@ func TestCaptureSingleAppLog_Truncated(t *testing.T) {
147147
require.NoError(t, os.WriteFile(filename, []byte(truncatedContent), 0644))
148148

149149
// Second call should detect truncation and reset the read position to 0, then copy the new content.
150-
res, err = appLog.CaptureSingleAppLog(filename, 123)
150+
_, err = appLog.CaptureSingleAppLog(filename, 123)
151151
require.NoError(t, err)
152152

153153
// Find the new destination file.

internal/capture/boomi.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ func fetchAtomConnectorDetails(boomiUserName, boomiPassword, boomiURL string) ([
277277

278278
// assign query token from the current response
279279
queryToken = queryResult.QueryToken
280-
281280
}
282281

283282
return records, nil
@@ -464,7 +463,6 @@ func (b *BoomiExecutionOutput) WriteAtomConnectorDetails(atomConnectors []AtomCo
464463
}
465464

466465
for _, atomConnector := range atomConnectors {
467-
468466
boomiData := fmt.Sprintf("%s,%s,%s\n", atomConnector.Type, atomConnector.Name, atomConnector.AtomType)
469467
_, err := b.file.WriteString(boomiData)
470468

@@ -501,13 +499,11 @@ func convertExecutionDurationToInt(record ExecutionRecord, jobStatus string) int
501499
// If the query token is NOT empty, it will hit queryMore URL with the query token
502500
// received from the previous request and finally return the response
503501
func makeBoomiRequest(queryToken string, username string, password string, boomiURL string) (*resty.Response, error) {
504-
505502
// Create a new Resty client
506503
client := resty.New()
507504

508505
// Set a hook to log the request
509506
client.OnBeforeRequest(func(c *resty.Client, req *resty.Request) error {
510-
511507
// Log the request body, if any
512508
if req.Body != nil {
513509
// We need to handle different types of body data
@@ -614,13 +610,11 @@ func makeBoomiRequest(queryToken string, username string, password string, boomi
614610
// If the query token is NOT empty, it will hit queryMore URL with the query token
615611
// received from the previous request and finally return the response
616612
func makeAtomConnectorsRequest(queryToken string, username string, password string, boomiURL string) (*resty.Response, error) {
617-
618613
// Create a new Resty client
619614
client := resty.New()
620615

621616
// Set a hook to log the request
622617
client.OnBeforeRequest(func(c *resty.Client, req *resty.Request) error {
623-
624618
// Log the request body, if any
625619
if req.Body != nil {
626620
// We need to handle different types of body data
@@ -861,5 +855,4 @@ func downloadAtomLog(username, password, boomiAcctId string) {
861855

862856
fmt.Println("File downloaded successfully ")
863857
}
864-
865858
}

internal/capture/dmesg.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func (d *DMesg) CaptureToFile() (*os.File, error) {
6464
// and falling back to the secondary command if needed.
6565
func (d *DMesg) captureOutput(file *os.File) error {
6666
if err := d.captureWithPrimaryCommand(file); err != nil {
67-
6867
// This fallback mechanism has been here since the beginning.
6968
// We keep the same logic with the refactor, but it seems to be not working.
7069

internal/capture/gc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (t *GC) Run() (result Result, err error) {
3939
}
4040

4141
if gcFile == nil && t.Pid > 0 {
42-
4342
if gcFile == nil {
4443
// Garbage collection log: Attempt 5: jstat
4544
logger.Log("Trying to capture gc log using jstat...")

0 commit comments

Comments
 (0)