Skip to content

Commit 555c538

Browse files
committed
Use 'nil' instead of empty map in 'catcher' calls system. Improve code readability and reduce memory allocation overhead.
1 parent 681d88b commit 555c538

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

sophos/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
)
1717

1818
func main() {
19-
catcher.Info("Starting sophos central module...", map[string]any{})
19+
catcher.Info("Starting sophos central module...", nil)
2020
intKey := configuration.GetInternalKey()
2121
panelServ := configuration.GetPanelServiceName()
2222
if intKey == "" || panelServ == "" {
23-
catcher.Error("Internal key or panel service name is not set. Exiting...", nil, map[string]any{})
23+
catcher.Error("Internal key or panel service name is not set. Exiting...", nil, nil)
2424
os.Exit(1)
2525
}
2626
client := utmconf.NewUTMClient(intKey, "http://"+panelServ)
@@ -33,7 +33,7 @@ func main() {
3333

3434
for range ticker.C {
3535
if err := utils.ConnectionChecker(configuration.CHECKCON); err != nil {
36-
catcher.Error("External connection failure detected", err, map[string]any{})
36+
catcher.Error("External connection failure detected", err, nil)
3737
}
3838

3939
endTime := time.Now().UTC()
@@ -45,10 +45,10 @@ func main() {
4545
moduleConfig, err := client.GetUTMConfig(enum.SOPHOS)
4646
if err != nil {
4747
if strings.Contains(err.Error(), "invalid character '<'") {
48-
catcher.Error("error getting configuration of the SOPHOS module: backend is not available", nil, map[string]any{})
48+
catcher.Error("error getting configuration of the SOPHOS module: backend is not available", nil, nil)
4949
}
5050
if strings.TrimSpace(err.Error()) != "" {
51-
catcher.Error("error getting configuration of the SOPHOS module", err, map[string]any{})
51+
catcher.Error("error getting configuration of the SOPHOS module", err, nil)
5252
}
5353
continue
5454
}

sophos/processor/processor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ func (p *SophosCentralProcessor) getAccessToken() (string, error) {
4848

4949
response, _, err := utils.DoReq[map[string]any](configuration.AUTHURL, []byte(data.Encode()), http.MethodPost, headers)
5050
if err != nil {
51-
return "", catcher.Error("error making auth request", err, map[string]any{})
51+
return "", catcher.Error("error making auth request", err, nil)
5252
}
5353

5454
accessToken, ok := response["access_token"].(string)
5555
if !ok || accessToken == "" {
56-
return "", catcher.Error("access_token not found in response", nil, map[string]any{})
56+
return "", catcher.Error("access_token not found in response", nil, nil)
5757
}
5858

5959
expiresIn, ok := response["expires_in"].(float64)
6060
if !ok {
61-
return "", catcher.Error("expires_in not found in response", nil, map[string]any{})
61+
return "", catcher.Error("expires_in not found in response", nil, nil)
6262
}
6363

6464
p.AccessToken = accessToken
@@ -84,16 +84,16 @@ func (p *SophosCentralProcessor) getTenantInfo(accessToken string) error {
8484

8585
response, _, err := utils.DoReq[WhoamiResponse](configuration.WHOAMIURL, nil, http.MethodGet, headers)
8686
if err != nil {
87-
return catcher.Error("error making whoami request", err, map[string]any{})
87+
return catcher.Error("error making whoami request", err, nil)
8888
}
8989

9090
if response.ID == "" {
91-
return catcher.Error("tenant ID not found in whoami response", nil, map[string]any{})
91+
return catcher.Error("tenant ID not found in whoami response", nil, nil)
9292
}
9393
p.TenantID = response.ID
9494

9595
if response.ApiHosts.DataRegion == "" {
96-
return catcher.Error("dataRegion not found in whoami response", nil, map[string]any{})
96+
return catcher.Error("dataRegion not found in whoami response", nil, nil)
9797
}
9898
p.DataRegion = response.ApiHosts.DataRegion
9999

@@ -122,12 +122,12 @@ type Pages struct {
122122
func (p *SophosCentralProcessor) getLogs(fromTime int64, nextKey string, group types.ModuleGroup) ([]TransformedLog, string, error) {
123123
accessToken, err := p.getValidAccessToken()
124124
if err != nil {
125-
return nil, "", catcher.Error("error getting access token", err, map[string]any{})
125+
return nil, "", catcher.Error("error getting access token", err, nil)
126126
}
127127

128128
if p.TenantID == "" || p.DataRegion == "" {
129129
if err := p.getTenantInfo(accessToken); err != nil {
130-
return nil, "", catcher.Error("error getting tenant information", err, map[string]any{})
130+
return nil, "", catcher.Error("error getting tenant information", err, nil)
131131
}
132132
}
133133

@@ -138,7 +138,7 @@ func (p *SophosCentralProcessor) getLogs(fromTime int64, nextKey string, group t
138138
for {
139139
u, err := p.buildURL(fromTime, currentNextKey)
140140
if err != nil {
141-
return nil, "", catcher.Error("error building URL", err, map[string]any{})
141+
return nil, "", catcher.Error("error building URL", err, nil)
142142
}
143143

144144
headers := map[string]string{

sophos/processor/sendData.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func SendToLogstash(data []TransformedLog) *logger.Error {
2929
for _, str := range data {
3030
body, err := json.Marshal(str)
3131
if err != nil {
32-
catcher.Error("error encoding log to JSON", err, map[string]any{})
32+
catcher.Error("error encoding log to JSON", err, nil)
3333
continue
3434
}
3535
if err := sendLogs(body); err != nil {
36-
catcher.Error("error sending logs to logstach", err, map[string]any{})
36+
catcher.Error("error sending logs to logstach", err, nil)
3737
continue
3838
}
3939
}
@@ -45,12 +45,12 @@ func sendLogs(log []byte) error {
4545

4646
req, err := http.NewRequest("POST", url, bytes.NewBuffer(log))
4747
if err != nil {
48-
return catcher.Error("error creating request", err, map[string]any{})
48+
return catcher.Error("error creating request", err, nil)
4949
}
5050

5151
resp, err := client.Do(req)
5252
if err != nil {
53-
return catcher.Error("error sending logs", err, map[string]any{})
53+
return catcher.Error("error sending logs", err, nil)
5454
}
5555
defer resp.Body.Close()
5656

0 commit comments

Comments
 (0)