Skip to content

Commit d3f94af

Browse files
authored
refact: remove unnecessary pointers to map, string, mutex (#4212)
1 parent 3e6f402 commit d3f94af

5 files changed

Lines changed: 21 additions & 23 deletions

File tree

cmd/notification-file/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
var (
2323
FileWriter *os.File
24-
FileWriteMutex *sync.Mutex
24+
FileWriteMutex sync.Mutex
2525
FileSize int64
2626
)
2727

@@ -231,8 +231,6 @@ func (s *FilePlugin) Configure(_ context.Context, config *protobufs.Config) (*pr
231231
return &protobufs.Empty{}, err
232232
}
233233

234-
FileWriteMutex = &sync.Mutex{}
235-
236234
FileWriter, err = os.OpenFile(d.LogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
237235
if err != nil {
238236
logger.Error("Failed to open log file", "error", err)

pkg/acquisition/modules/http/config.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import (
1818
)
1919

2020
type Configuration struct {
21-
// IPFilter []string `yaml:"ip_filter"`
22-
// ChunkSize *int64 `yaml:"chunk_size"`
23-
ListenAddr string `yaml:"listen_addr"`
24-
ListenSocket string `yaml:"listen_socket"`
25-
Path string `yaml:"path"`
26-
AuthType string `yaml:"auth_type"`
27-
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
28-
Headers *map[string]string `yaml:"headers"`
29-
TLS *TLSConfig `yaml:"tls"`
30-
CustomStatusCode *int `yaml:"custom_status_code"`
31-
CustomHeaders *map[string]string `yaml:"custom_headers"`
32-
MaxBodySize *int64 `yaml:"max_body_size"`
33-
Timeout *time.Duration `yaml:"timeout"`
34-
configuration.DataSourceCommonCfg `yaml:",inline"`
21+
// IPFilter []string `yaml:"ip_filter"`
22+
// ChunkSize *int64 `yaml:"chunk_size"`
23+
ListenAddr string `yaml:"listen_addr"`
24+
ListenSocket string `yaml:"listen_socket"`
25+
Path string `yaml:"path"`
26+
AuthType string `yaml:"auth_type"`
27+
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
28+
Headers map[string]string `yaml:"headers"`
29+
TLS *TLSConfig `yaml:"tls"`
30+
CustomStatusCode *int `yaml:"custom_status_code"`
31+
CustomHeaders map[string]string `yaml:"custom_headers"`
32+
MaxBodySize *int64 `yaml:"max_body_size"`
33+
Timeout *time.Duration `yaml:"timeout"`
34+
configuration.DataSourceCommonCfg `yaml:",inline"`
3535
}
3636

3737
func ConfigurationFromYAML(y []byte) (Configuration, error) {

pkg/acquisition/modules/http/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func authorizeRequest(r *http.Request, hc *Configuration) error {
3737
}
3838

3939
if hc.AuthType == "headers" {
40-
for key, value := range *hc.Headers {
40+
for key, value := range hc.Headers {
4141
if r.Header.Get(key) != value {
4242
return errors.New("invalid headers")
4343
}
@@ -169,7 +169,7 @@ func (s *Source) RunServer(ctx context.Context, out chan pipeline.Event, t *tomb
169169
}
170170

171171
if s.Config.CustomHeaders != nil {
172-
for key, value := range *s.Config.CustomHeaders {
172+
for key, value := range s.Config.CustomHeaders {
173173
w.Header().Set(key, value)
174174
}
175175
}

pkg/enrichment/dataprovider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type DataProvider struct {
1010
Type string `yaml:"type"`
1111
//Control cache strategy on expensive regexps
1212
Cache *bool `yaml:"cache"`
13-
Strategy *string `yaml:"strategy"`
13+
Strategy string `yaml:"strategy"`
1414
Size *int `yaml:"size"`
1515
TTL *time.Duration `yaml:"ttl"`
1616
}

pkg/exprhelpers/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
143143
return nil
144144
}
145145
// cache is implicitly disabled if no cache config is provided
146-
if cacheCfg.Strategy == nil && cacheCfg.TTL == nil && cacheCfg.Size == nil {
146+
if cacheCfg.Strategy == "" && cacheCfg.TTL == nil && cacheCfg.Size == nil {
147147
return nil
148148
}
149149
// cache is enabled
@@ -156,8 +156,8 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
156156
gc := gcache.New(size)
157157

158158
strategy := "LRU"
159-
if cacheCfg.Strategy != nil {
160-
strategy = *cacheCfg.Strategy
159+
if cacheCfg.Strategy != "" {
160+
strategy = cacheCfg.Strategy
161161
}
162162

163163
switch strategy {

0 commit comments

Comments
 (0)