Skip to content

Commit 63a84ef

Browse files
committed
Use 'nil' instead of empty map in 'catcher' calls system. Improve code readability and reduce memory allocation overhead.
1 parent cc4d578 commit 63a84ef

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

bitdefender/configuration/config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ConfigureModules(cnf *types.ConfigurationSection, mutex *sync.Mutex) {
3838
time.Sleep(delayCheckConfig)
3939

4040
if err := utils.ConnectionChecker(constants.URL_CHECK_CONNECTION); err != nil {
41-
catcher.Error("Failed to establish connection", err, map[string]any{})
41+
catcher.Error("Failed to establish connection", err, nil)
4242
}
4343

4444
tempModuleConfig, err := client.GetUTMConfig(enum.BITDEFENDER)
@@ -47,7 +47,7 @@ func ConfigureModules(cnf *types.ConfigurationSection, mutex *sync.Mutex) {
4747
continue
4848
}
4949
if (err.Error() != "") && (err.Error() != " ") {
50-
catcher.Error("error getting configuration of the Bitdefender module", err, map[string]any{})
50+
catcher.Error("error getting configuration of the Bitdefender module", err, nil)
5151
}
5252
continue
5353
}
@@ -61,16 +61,16 @@ func ConfigureModules(cnf *types.ConfigurationSection, mutex *sync.Mutex) {
6161
if !araAnyEmpty(group.Configurations[0].ConfValue, group.Configurations[1].ConfValue, group.Configurations[2].ConfValue, group.Configurations[3].ConfValue) {
6262
catcher.Info("new configuration found", map[string]any{"groupName": group.GroupName, "master": group.Configurations[2].ConfValue, "CompanyIDs": group.Configurations[3].ConfValue})
6363
if err := confBDGZApiPush(group, "sendConf"); err != nil {
64-
catcher.Error("error sending configuration", err, map[string]any{})
64+
catcher.Error("error sending configuration", err, nil)
6565
continue
6666
}
6767
time.Sleep(15 * time.Second)
6868
if err := confBDGZApiPush(group, "getConf"); err != nil {
69-
catcher.Error("error getting configuration", err, map[string]any{})
69+
catcher.Error("error getting configuration", err, nil)
7070
continue
7171
}
7272
if err := confBDGZApiPush(group, "sendTest"); err != nil {
73-
catcher.Error("error sending test event", err, map[string]any{})
73+
catcher.Error("error sending test event", err, nil)
7474
continue
7575
}
7676

@@ -101,7 +101,7 @@ func confBDGZApiPush(config types.ModuleGroup, operation string) error {
101101
for i := 0; i < 5; i++ {
102102
response, err := fn(config)
103103
if err != nil {
104-
catcher.Error("error sending configuration", err, map[string]any{})
104+
catcher.Error("error sending configuration", err, nil)
105105
time.Sleep(1 * time.Minute)
106106
continue
107107
}
@@ -114,7 +114,7 @@ func confBDGZApiPush(config types.ModuleGroup, operation string) error {
114114
regex := regexp.MustCompile(`result":true`)
115115
match := regex.Match([]byte(string(myBody)))
116116
if match {
117-
catcher.Info("Configuration sent correctly", map[string]any{})
117+
catcher.Info("Configuration sent correctly", nil)
118118
}
119119
}
120120
return nil
@@ -123,33 +123,33 @@ func confBDGZApiPush(config types.ModuleGroup, operation string) error {
123123
}
124124

125125
func sendPushEventSettings(config types.ModuleGroup) (*http.Response, error) {
126-
catcher.Info("Sending configuration...", map[string]any{})
126+
catcher.Info("Sending configuration...", nil)
127127
byteTemplate := getTemplateSetPush(config)
128128
body, err := json.Marshal(byteTemplate)
129129
if err != nil {
130-
catcher.Error("error when marshaling the request body to send the configuration", err, map[string]any{})
130+
catcher.Error("error when marshaling the request body to send the configuration", err, nil)
131131
return nil, err
132132
}
133133
return sendRequest(body, config)
134134
}
135135

136136
func getPushEventSettings(config types.ModuleGroup) (*http.Response, error) {
137-
catcher.Info("Checking configuration...", map[string]any{})
137+
catcher.Info("Checking configuration...", nil)
138138
byteTemplate := getTemplateGet()
139139
body, err := json.Marshal(byteTemplate)
140140
if err != nil {
141-
catcher.Error("error when marshaling the request body to send the configuration", err, map[string]any{})
141+
catcher.Error("error when marshaling the request body to send the configuration", err, nil)
142142
return nil, err
143143
}
144144
return sendRequest(body, config)
145145
}
146146

147147
func sendTestPushEvent(config types.ModuleGroup) (*http.Response, error) {
148-
catcher.Info("Sending Event Test...", map[string]any{})
148+
catcher.Info("Sending Event Test...", nil)
149149
byteTemplate := getTemplateTest()
150150
body, err := json.Marshal(byteTemplate)
151151
if err != nil {
152-
catcher.Error("error when marshaling the request body to send the configuration", err, map[string]any{})
152+
catcher.Error("error when marshaling the request body to send the configuration", err, nil)
153153
return nil, err
154154
}
155155
return sendRequest(body, config)

bitdefender/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ var (
2222
func main() {
2323
path, err := utils.GetMyPath()
2424
if err != nil {
25-
catcher.Error("failed to get current path", err, map[string]any{})
25+
catcher.Error("failed to get current path", err, nil)
2626
os.Exit(1)
2727
}
2828

2929
certsPath := filepath.Join(path, "certs")
3030
err = utils.CreatePathIfNotExist(certsPath)
3131
if err != nil {
32-
catcher.Error("error creating path", err, map[string]any{})
32+
catcher.Error("error creating path", err, nil)
3333
os.Exit(1)
3434
}
3535

3636
err = utils.GenerateCerts(certsPath)
3737
if err != nil {
38-
catcher.Error("error generating certificates", err, map[string]any{})
38+
catcher.Error("error generating certificates", err, nil)
3939
os.Exit(1)
4040
}
4141

bitdefender/server/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ var syslogHelper EpsSyslogHelper
2020
// GetBDGZLogs gets the Bitdefender Api Push logs and sends them to the syslog server
2121
func GetBDGZLogs(config *types.ConfigurationSection) http.HandlerFunc {
2222
return func(w http.ResponseWriter, r *http.Request) {
23-
catcher.Info("New group of events received", map[string]any{})
23+
catcher.Info("New group of events received", nil)
2424
// Check if the Bitdefender Module is active
2525
if config.ModuleActive {
2626
//Check if the authorization exist
2727
if r.Header.Get("authorization") == "" {
2828
messag := "401 Missing Authorization Header"
29-
catcher.Error(messag, nil, map[string]any{})
29+
catcher.Error(messag, nil, nil)
3030
j, _ := json.Marshal(messag)
3131
w.WriteHeader(http.StatusUnauthorized)
3232
w.Write(j)
@@ -42,7 +42,7 @@ func GetBDGZLogs(config *types.ConfigurationSection) http.HandlerFunc {
4242
}
4343
if !isAuth {
4444
messag := "401 Invalid Authentication Credentials"
45-
catcher.Error(messag, nil, map[string]any{})
45+
catcher.Error(messag, nil, nil)
4646
j, _ := json.Marshal(messag)
4747
w.WriteHeader(http.StatusUnauthorized)
4848
w.Write(j)
@@ -53,7 +53,7 @@ func GetBDGZLogs(config *types.ConfigurationSection) http.HandlerFunc {
5353
var newBody schema.BodyEvents
5454
err := json.NewDecoder(r.Body).Decode(&newBody)
5555
if err != nil {
56-
catcher.Error("error to decode body", err, map[string]any{})
56+
catcher.Error("error to decode body", err, nil)
5757
return
5858
}
5959

@@ -66,7 +66,7 @@ func GetBDGZLogs(config *types.ConfigurationSection) http.HandlerFunc {
6666
w.WriteHeader(http.StatusOK)
6767
w.Write(j)
6868
} else {
69-
catcher.Error("Bitdefender module disabled", nil, map[string]any{})
69+
catcher.Error("Bitdefender module disabled", nil, nil)
7070
}
7171
}
7272
}
@@ -99,7 +99,7 @@ func ServerUp(cnf *types.ConfigurationSection, certsPath string) {
9999
catcher.Info("Listening in port", map[string]any{"port": constants.GetConnectorPort()})
100100
err := server.ListenAndServeTLS(filepath.Join(certsPath, "server.crt"), filepath.Join(certsPath, "server.key"))
101101
if err != nil {
102-
catcher.Error("error starting server", err, map[string]any{})
102+
catcher.Error("error starting server", err, nil)
103103
}
104104
//Close connection with syslogServer
105105
syslogHelper.clientSyslog.Close()

bitdefender/server/syslog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (g *EpsSyslogHelper) SentToSyslog(config *types.ConfigurationSection, event
3838
pattern := "BitdefenderGZCompanyId=" + compID
3939
match, err := regexp.MatchString(pattern, syslogMessage)
4040
if err != nil {
41-
catcher.Error("error matching pattern", err, map[string]any{})
41+
catcher.Error("error matching pattern", err, nil)
4242
continue
4343
}
4444
if match {

0 commit comments

Comments
 (0)