Skip to content

Commit cb04d7b

Browse files
committed
Address some golangci-lint issues
1 parent f916ab8 commit cb04d7b

File tree

5 files changed

+27
-131
lines changed

5 files changed

+27
-131
lines changed

internal/agent/ondemand/ondemand.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ func writeMetaInfo(processId int, appName, endpoint, tags string) (msg string, o
904904
timestamp := now.Format("2006-01-02T15-04-05")
905905
timezone, _ := now.Zone()
906906
cpuCount := runtime.NumCPU()
907-
_, e = file.WriteString(fmt.Sprintf(metaInfoTemplate, hostname, processId, appName, un, timestamp, timezone, timezoneIANA, cpuCount, jv, ov, tags))
907+
_, e = fmt.Fprintf(file, metaInfoTemplate, hostname, processId, appName, un, timestamp, timezone, timezoneIANA, cpuCount, jv, ov, tags)
908908
if e != nil {
909909
err = fmt.Errorf("write result err: %v, previous err: %v", e, err)
910910
return
@@ -1039,7 +1039,7 @@ func ExtractGCLogPathFromCmdline(cmdline string) string {
10391039

10401040
if logFile == "" {
10411041
// Garbage collection log: Attempt 1: -Xloggc:<file-path>
1042-
re := regexp.MustCompile("-Xloggc:(\\S+)")
1042+
re := regexp.MustCompile(`-Xloggc:(\S+)`)
10431043
matches := re.FindSubmatch(cmdlineBytes)
10441044
if len(matches) == 2 {
10451045
logFile = string(matches[1])
@@ -1051,7 +1051,7 @@ func ExtractGCLogPathFromCmdline(cmdline string) string {
10511051
// -Xlog[:option]
10521052
// option := [<what>][:[<output>][:[<decorators>][:<output-options>]]]
10531053
// https://openjdk.org/jeps/158
1054-
re := regexp.MustCompile("-Xlog:gc\\S*:file=(\\S+)")
1054+
re := regexp.MustCompile(`-Xlog:gc\S*:file=(\S+)`)
10551055
matches := re.FindSubmatch(cmdlineBytes)
10561056
if len(matches) == 2 {
10571057
logFile = string(matches[1])
@@ -1064,7 +1064,7 @@ func ExtractGCLogPathFromCmdline(cmdline string) string {
10641064

10651065
if logFile == "" {
10661066
// Garbage collection log: Attempt 3: -Xlog:gc:<file-path>
1067-
re := regexp.MustCompile("-Xlog:gc:(\\S+)")
1067+
re := regexp.MustCompile(`-Xlog:gc:(\S+)`)
10681068
matches := re.FindSubmatch(cmdlineBytes)
10691069
if len(matches) == 2 {
10701070
logFile = string(matches[1])
@@ -1077,7 +1077,7 @@ func ExtractGCLogPathFromCmdline(cmdline string) string {
10771077

10781078
if logFile == "" {
10791079
// Garbage collection log: Attempt 4: -Xverbosegclog:/tmp/buggy-app-gc-log.%pid.log,20,10
1080-
re := regexp.MustCompile("-Xverbosegclog:(\\S+)")
1080+
re := regexp.MustCompile(`-Xverbosegclog:(\S+)`)
10811081
matches := re.FindSubmatch(cmdlineBytes)
10821082
if len(matches) == 2 {
10831083
logFile = string(matches[1])

internal/capture/boomi.go

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func CaptureBoomiDetails(endpoint string, timestamp string, pid int) {
163163

164164
///// get atom connector details
165165
atomConnectorURL := "https://api.boomi.com/api/rest/v1/" + accountID + "/Connector/query"
166-
atomConnectorRecord, err := fetchAtomConnectorDetails(boomiUserName, boomiPassword, atomConnectorURL)
166+
atomConnectorRecord, _ := fetchAtomConnectorDetails(boomiUserName, boomiPassword, atomConnectorURL)
167167

168168
//// download atom log
169169
downloadAtomLog(boomiUserName, boomiPassword, accountID)
@@ -185,7 +185,7 @@ func fetchBoomiExecutionRecords(boomiUserName, boomiPassword, boomiURL string) (
185185
resp, err := makeBoomiRequest(queryToken, boomiUserName, boomiPassword, boomiURL)
186186

187187
if err != nil {
188-
return records, fmt.Errorf("Failed to make Boomi request: %w", err)
188+
return records, fmt.Errorf("failed to make Boomi request: %w", err)
189189
}
190190
logger.Log("Response Status Code: %d", resp.StatusCode())
191191

@@ -199,7 +199,7 @@ func fetchBoomiExecutionRecords(boomiUserName, boomiPassword, boomiURL string) (
199199
var queryResult BoomiExecutionRecordQueryResult
200200
jsonErr := json.Unmarshal(resp.Body(), &queryResult)
201201
if jsonErr != nil {
202-
return records, fmt.Errorf("Error unmarshalling Boomi response as JSON: %w", jsonErr)
202+
return records, fmt.Errorf("error unmarshalling Boomi response as JSON: %w", jsonErr)
203203
}
204204

205205
logger.Log("Length of Boomi queryResult.Result->%d", len(queryResult.Result))
@@ -238,11 +238,7 @@ func fetchAtomConnectorDetails(boomiUserName, boomiPassword, boomiURL string) ([
238238
stopped := false
239239
queryToken := ""
240240
for {
241-
resp, err := makeAtomConnectorsRequest(queryToken, boomiUserName, boomiPassword, boomiURL)
242-
243-
if err != nil {
244-
//return fmt.Errorf("Failed to make Boomi request: %w", err)
245-
}
241+
resp, _ := makeAtomConnectorsRequest(queryToken, boomiUserName, boomiPassword, boomiURL)
246242
logger.Log("Response Status Code: %d", resp.StatusCode())
247243

248244
// return if status code is not 200
@@ -255,7 +251,7 @@ func fetchAtomConnectorDetails(boomiUserName, boomiPassword, boomiURL string) ([
255251
var queryResult AtomConnectorRecordQueryResult
256252
jsonErr := json.Unmarshal(resp.Body(), &queryResult)
257253
if jsonErr != nil {
258-
return records, fmt.Errorf("Error unmarshalling Boomi response as JSON: %w", jsonErr)
254+
return records, fmt.Errorf("error unmarshalling Boomi response as JSON: %w", jsonErr)
259255
}
260256
logger.Log("Length of Boomi queryResult.Result->%d", len(queryResult.Result))
261257
if len(queryResult.Result) <= 0 {
@@ -338,7 +334,7 @@ type BoomiExecutionOutput struct {
338334
func (b *BoomiExecutionOutput) CreateFile() (*os.File, error) {
339335
file, err := os.Create("boomi.out")
340336
if err != nil {
341-
return nil, fmt.Errorf("Error while creating Boomi output file: %w", err)
337+
return nil, fmt.Errorf("error while creating Boomi output file: %w", err)
342338
}
343339

344340
b.file = file
@@ -731,23 +727,6 @@ func getAtomQueryDetails(accountID string, username string, password string) Ato
731727
return atomQueryResult
732728
}
733729

734-
func getAtomConnectorDetails(accountID string, username string, password string) {
735-
// Create a new Resty client
736-
client := resty.New()
737-
connectorURL := "https://api.boomi.com/api/rest/v1/" + accountID + "/Connector/query"
738-
resp, err := client.R().
739-
SetBasicAuth(username, password).
740-
SetHeader(BoomiRequestAccept, BoomiRequestApplicationJSON).
741-
Post(connectorURL)
742-
743-
if err != nil {
744-
logger.Log("error while calling atom connector details rest endpoint %s", err.Error())
745-
}
746-
747-
logger.Log("atom connector result status code %d", resp.StatusCode())
748-
749-
}
750-
751730
// use the following URL to download the container id
752731
// https://api.boomi.com/mdm/api/rest/v1/<account_id/clouds
753732
// this will return a similar response like this
@@ -793,7 +772,7 @@ func downloadAtomLog(username, password, boomiAcctId string) {
793772
boomiURL := "https://api.boomi.com/api/rest/v1/" + boomiAcctId + "/AtomLog"
794773
logger.Log("boomi atom log req string %s", result.String())
795774

796-
resp, err := client.R().
775+
resp, _ := client.R().
797776
SetBasicAuth(username, password).
798777
SetHeader(BoomiRequestContentType, BoomiRequestApplicationJSON).
799778
SetBody(result.String()).
@@ -884,83 +863,3 @@ func downloadAtomLog(username, password, boomiAcctId string) {
884863
}
885864

886865
}
887-
888-
// downloads the atom diskspace details from the Boomi server
889-
func getAtomDiskSize(accountID string, atomId string, username string, password string, records []ExecutionRecord) {
890-
891-
uniqueData := make(map[string]struct{})
892-
// Create a slice to store unique values
893-
var atomIDResult []string
894-
// iterate through all the execution records and store the atom id
895-
for _, executionRecord := range records {
896-
atomID := executionRecord.AtomID
897-
if _, exists := uniqueData[atomID]; !exists {
898-
uniqueData[atomID] = struct{}{} // Add to map
899-
atomIDResult = append(atomIDResult, atomID) // Add to slice
900-
}
901-
}
902-
903-
logger.Log("atomIDResult->%s", atomIDResult)
904-
// Create a new Resty client
905-
client := resty.New()
906-
907-
/// iterate through iterate through the atomIDResult and download the atom diskspace information
908-
var atomURL string
909-
for _, atmID := range atomIDResult {
910-
atomURL = "https://api.boomi.com/api/rest/v1/" + accountID + "/async/AtomDiskSpace/"
911-
resp, err := client.R().
912-
SetBasicAuth(username, password).
913-
SetHeader(BoomiRequestAccept, BoomiRequestApplicationJSON).
914-
SetBody(atmID).
915-
Post(atomURL)
916-
917-
if err != nil {
918-
logger.Log("error while calling atom asycn rest endpoint %s", err.Error())
919-
}
920-
921-
logger.Log("atom disk space status code %d", resp.StatusCode())
922-
// return if status code is not 200
923-
if resp.StatusCode() != 202 {
924-
logger.Log("Boomi API responded with non 202, aborting...")
925-
return
926-
}
927-
928-
// unmarshal the JSON response into the struct
929-
var asyncToken AsyncToken
930-
jsonErr := json.Unmarshal(resp.Body(), &asyncToken)
931-
if jsonErr != nil {
932-
return
933-
}
934-
logger.Log("atom async response->%s", jsonErr)
935-
936-
/// now call the atom disk space rest endpoint
937-
if asyncToken.Token != "" {
938-
atomURL = "https://api.boomi.com/api/rest/v1/" + accountID + "/async/AtomDiskSpace/response/" + asyncToken.Token
939-
940-
resp, err := client.R().
941-
SetBasicAuth(username, password).
942-
SetHeader(BoomiRequestAccept, BoomiRequestApplicationJSON).
943-
Get(atomURL)
944-
945-
if err != nil {
946-
logger.Log("error while applying template with value %s", err.Error())
947-
}
948-
949-
// return if status code is not 200
950-
if resp.StatusCode() != 200 {
951-
logger.Log("Boomi API responded with non 200, aborting...")
952-
return
953-
}
954-
955-
var asyncAtomDiskspaceTokenResult AsyncAtomDiskspaceTokenResult
956-
jsonErr := json.Unmarshal(resp.Body(), &asyncAtomDiskspaceTokenResult)
957-
if jsonErr != nil {
958-
logger.Log("error while unmarshalling response %s", jsonErr.Error())
959-
return
960-
}
961-
logger.Log("asyncAtomDiskspaceTokenResult %v", asyncAtomDiskspaceTokenResult)
962-
}
963-
964-
}
965-
966-
}

internal/capture/executils/cmd.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,23 @@ func (c *WaitCmd) SetStdoutAndStderr(writer io.Writer) {
2929
if c.Cmd == nil {
3030
return
3131
}
32-
c.Cmd.Stdout = writer
33-
c.Cmd.Stderr = writer
32+
c.Stdout = writer
33+
c.Stderr = writer
3434
}
3535

3636
func (c *WaitCmd) GetPid() int {
37-
if c.Cmd == nil || c.Cmd.Process == nil {
37+
if c.Cmd == nil || c.Process == nil {
3838
return -1
3939
}
40-
return c.Cmd.Process.Pid
40+
return c.Process.Pid
4141
}
4242

4343
func (c *WaitCmd) KillAndWait() (err error) {
4444
return
4545
}
4646

4747
func (c *WaitCmd) IsSkipped() bool {
48-
if c.Cmd == nil {
49-
return true
50-
}
51-
return false
48+
return c.Cmd == nil
5249
}
5350

5451
func (c *WaitCmd) Wait() (err error) {
@@ -64,7 +61,7 @@ func (c *WaitCmd) ExitCode() (code int) {
6461
code = -1
6562
return
6663
}
67-
code = c.Cmd.ProcessState.ExitCode()
64+
code = c.ProcessState.ExitCode()
6865
return
6966
}
7067

@@ -88,10 +85,10 @@ type Cmd struct {
8885
}
8986

9087
func (c *Cmd) KillAndWait() (err error) {
91-
if c.Cmd == nil || c.Cmd.Process == nil {
88+
if c.Cmd == nil || c.Process == nil {
9289
return
9390
}
94-
err = c.Cmd.Process.Kill()
91+
err = c.Process.Kill()
9592
if err != nil {
9693
return
9794
}
@@ -100,17 +97,17 @@ func (c *Cmd) KillAndWait() (err error) {
10097
}
10198

10299
func (c *Cmd) Interrupt() (err error) {
103-
if c.Cmd == nil || c.Cmd.Process == nil {
100+
if c.Cmd == nil || c.Process == nil {
104101
return
105102
}
106-
err = c.Cmd.Process.Signal(os.Interrupt)
103+
err = c.Process.Signal(os.Interrupt)
107104
return
108105
}
109106

110107
func (c *Cmd) Kill() (err error) {
111-
if c.Cmd == nil || c.Cmd.Process == nil {
108+
if c.Cmd == nil || c.Process == nil {
112109
return
113110
}
114-
err = c.Cmd.Process.Kill()
111+
err = c.Process.Kill()
115112
return
116113
}

internal/capture/executils/shell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
type Command []string
1919

2020
var NopCommand Command = nil
21-
var SkippedNopCommandError = errors.New("skipped nop command")
21+
var ErrSkippedNopCommandError = errors.New("skipped nop command")
2222

2323
const DynamicArg = "<DynamicArg>"
2424
const WaitCommand = "<WaitCommand>"
@@ -109,7 +109,7 @@ func NewCommand(cmd Command, hookers ...Hooker) CmdManager {
109109
func CommandCombinedOutput(cmd Command, hookers ...Hooker) ([]byte, error) {
110110
c := NewCommand(cmd, hookers...)
111111
if c.IsSkipped() {
112-
return nil, SkippedNopCommandError
112+
return nil, ErrSkippedNopCommandError
113113
}
114114
return c.CombinedOutput()
115115
}

internal/capture/healthcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (h *HealthCheck) runHTTPHealthCheck(ctx context.Context) (*http.Response, t
171171
// Check specifically for timeout errors
172172
if err != nil {
173173
if ctx.Err() == context.DeadlineExceeded {
174-
return nil, rtt, fmt.Errorf("Timeout occurred while waiting for a response from %s. The endpoint did not respond within %d seconds",
174+
return nil, rtt, fmt.Errorf("timeout occurred while waiting for a response from %s. The endpoint did not respond within %d seconds",
175175
h.Cfg.Endpoint,
176176
h.Cfg.TimeoutSecs)
177177
}

0 commit comments

Comments
 (0)