refact: remove unnecessary pointers to map, string, mutex (#4212)

This commit is contained in:
mmetc
2026-01-23 21:19:24 +01:00
committed by GitHub
parent 3e6f402373
commit d3f94af25b
5 changed files with 21 additions and 23 deletions
+1 -3
View File
@@ -21,7 +21,7 @@ import (
var (
FileWriter *os.File
FileWriteMutex *sync.Mutex
FileWriteMutex sync.Mutex
FileSize int64
)
@@ -231,8 +231,6 @@ func (s *FilePlugin) Configure(_ context.Context, config *protobufs.Config) (*pr
return &protobufs.Empty{}, err
}
FileWriteMutex = &sync.Mutex{}
FileWriter, err = os.OpenFile(d.LogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
logger.Error("Failed to open log file", "error", err)
+14 -14
View File
@@ -18,20 +18,20 @@ import (
)
type Configuration struct {
// IPFilter []string `yaml:"ip_filter"`
// ChunkSize *int64 `yaml:"chunk_size"`
ListenAddr string `yaml:"listen_addr"`
ListenSocket string `yaml:"listen_socket"`
Path string `yaml:"path"`
AuthType string `yaml:"auth_type"`
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
Headers *map[string]string `yaml:"headers"`
TLS *TLSConfig `yaml:"tls"`
CustomStatusCode *int `yaml:"custom_status_code"`
CustomHeaders *map[string]string `yaml:"custom_headers"`
MaxBodySize *int64 `yaml:"max_body_size"`
Timeout *time.Duration `yaml:"timeout"`
configuration.DataSourceCommonCfg `yaml:",inline"`
// IPFilter []string `yaml:"ip_filter"`
// ChunkSize *int64 `yaml:"chunk_size"`
ListenAddr string `yaml:"listen_addr"`
ListenSocket string `yaml:"listen_socket"`
Path string `yaml:"path"`
AuthType string `yaml:"auth_type"`
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
Headers map[string]string `yaml:"headers"`
TLS *TLSConfig `yaml:"tls"`
CustomStatusCode *int `yaml:"custom_status_code"`
CustomHeaders map[string]string `yaml:"custom_headers"`
MaxBodySize *int64 `yaml:"max_body_size"`
Timeout *time.Duration `yaml:"timeout"`
configuration.DataSourceCommonCfg `yaml:",inline"`
}
func ConfigurationFromYAML(y []byte) (Configuration, error) {
+2 -2
View File
@@ -37,7 +37,7 @@ func authorizeRequest(r *http.Request, hc *Configuration) error {
}
if hc.AuthType == "headers" {
for key, value := range *hc.Headers {
for key, value := range hc.Headers {
if r.Header.Get(key) != value {
return errors.New("invalid headers")
}
@@ -169,7 +169,7 @@ func (s *Source) RunServer(ctx context.Context, out chan pipeline.Event, t *tomb
}
if s.Config.CustomHeaders != nil {
for key, value := range *s.Config.CustomHeaders {
for key, value := range s.Config.CustomHeaders {
w.Header().Set(key, value)
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ type DataProvider struct {
Type string `yaml:"type"`
//Control cache strategy on expensive regexps
Cache *bool `yaml:"cache"`
Strategy *string `yaml:"strategy"`
Strategy string `yaml:"strategy"`
Size *int `yaml:"size"`
TTL *time.Duration `yaml:"ttl"`
}
+3 -3
View File
@@ -143,7 +143,7 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
return nil
}
// cache is implicitly disabled if no cache config is provided
if cacheCfg.Strategy == nil && cacheCfg.TTL == nil && cacheCfg.Size == nil {
if cacheCfg.Strategy == "" && cacheCfg.TTL == nil && cacheCfg.Size == nil {
return nil
}
// cache is enabled
@@ -156,8 +156,8 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
gc := gcache.New(size)
strategy := "LRU"
if cacheCfg.Strategy != nil {
strategy = *cacheCfg.Strategy
if cacheCfg.Strategy != "" {
strategy = cacheCfg.Strategy
}
switch strategy {