Skip to content

Commit

Permalink
lint: gocritic/typeDefFirst (ensure type definitions come before meth…
Browse files Browse the repository at this point in the history
…ods)
  • Loading branch information
mmetc committed Feb 4, 2025
1 parent bfed861 commit 5348591
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ linters-settings:
gocritic:
enable-all: true
disabled-checks:
- typeDefFirst
- paramTypeCombine
- httpNoBody
- ifElseChain
Expand Down
14 changes: 7 additions & 7 deletions cmd/crowdsec-cli/clialert/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/types"
)

type configGetter func() *csconfig.Config

type cliAlerts struct {
client *apiclient.ApiClient
cfg configGetter
}

func decisionsFromAlert(alert *models.Alert) string {
ret := ""
decMap := make(map[string]int)
Expand Down Expand Up @@ -183,13 +190,6 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
return nil
}

type configGetter func() *csconfig.Config

type cliAlerts struct {
client *apiclient.ApiClient
cfg configGetter
}

func New(getconfig configGetter) *cliAlerts {
return &cliAlerts{
cfg: getconfig,
Expand Down
14 changes: 7 additions & 7 deletions cmd/crowdsec-cli/clidecision/decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/types"
)

type configGetter func() *csconfig.Config

type cliDecisions struct {
client *apiclient.ApiClient
cfg configGetter
}

func (cli *cliDecisions) decisionsToTable(alerts *models.GetAlertsResponse, printMachine bool) error {
/*here we cheat a bit : to make it more readable for the user, we dedup some entries*/
spamLimit := make(map[string]bool)
Expand Down Expand Up @@ -115,13 +122,6 @@ func (cli *cliDecisions) decisionsToTable(alerts *models.GetAlertsResponse, prin
return nil
}

type configGetter func() *csconfig.Config

type cliDecisions struct {
client *apiclient.ApiClient
cfg configGetter
}

func New(cfg configGetter) *cliDecisions {
return &cliDecisions{
cfg: cfg,
Expand Down
12 changes: 6 additions & 6 deletions cmd/crowdsec-cli/clisupport/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func stripAnsiString(str string) string {
return reStripAnsi.ReplaceAllString(str, "")
}

type configGetter func() *csconfig.Config

type cliSupport struct {
cfg configGetter
}

func (cli *cliSupport) dumpMetrics(ctx context.Context, db *database.Client, zw *zip.Writer) error {
log.Info("Collecting prometheus metrics")

Expand Down Expand Up @@ -393,12 +399,6 @@ func (cli *cliSupport) dumpCrash(zw *zip.Writer) error {
return nil
}

type configGetter func() *csconfig.Config

type cliSupport struct {
cfg configGetter
}

func New(cfg configGetter) *cliSupport {
return &cliSupport{
cfg: cfg,
Expand Down
60 changes: 30 additions & 30 deletions pkg/csconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,36 @@ func (l *LocalApiClientCfg) Load() error {
return nil
}

/*local api service configuration*/
type LocalApiServerCfg struct {
Enable *bool `yaml:"enable"`
ListenURI string `yaml:"listen_uri,omitempty"` // 127.0.0.1:8080
ListenSocket string `yaml:"listen_socket,omitempty"`
TLS *TLSCfg `yaml:"tls"`
DbConfig *DatabaseCfg `yaml:"-"`
LogDir string `yaml:"-"`
LogMedia string `yaml:"-"`
OnlineClient *OnlineApiClientCfg `yaml:"online_client"`
ProfilesPath string `yaml:"profiles_path,omitempty"`
ConsoleConfigPath string `yaml:"console_path,omitempty"`
ConsoleConfig *ConsoleConfig `yaml:"-"`
Profiles []*ProfileCfg `yaml:"-"`
LogLevel *log.Level `yaml:"log_level"`
UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"`
TrustedProxies *[]string `yaml:"trusted_proxies,omitempty"`
CompressLogs *bool `yaml:"-"`
LogMaxSize int `yaml:"-"`
LogMaxAge int `yaml:"-"`
LogMaxFiles int `yaml:"-"`
LogFormat string `yaml:"-"`
TrustedIPs []string `yaml:"trusted_ips,omitempty"`
PapiLogLevel *log.Level `yaml:"papi_log_level"`
DisableRemoteLapiRegistration bool `yaml:"disable_remote_lapi_registration,omitempty"`
CapiWhitelistsPath string `yaml:"capi_whitelists_path,omitempty"`
CapiWhitelists *CapiWhitelist `yaml:"-"`
AutoRegister *LocalAPIAutoRegisterCfg `yaml:"auto_registration,omitempty"`
}

func (c *LocalApiServerCfg) GetTrustedIPs() ([]net.IPNet, error) {
trustedIPs := make([]net.IPNet, 0)

Expand Down Expand Up @@ -250,36 +280,6 @@ type LocalAPIAutoRegisterCfg struct {
AllowedRangesParsed []*net.IPNet `yaml:"-"`
}

/*local api service configuration*/
type LocalApiServerCfg struct {
Enable *bool `yaml:"enable"`
ListenURI string `yaml:"listen_uri,omitempty"` // 127.0.0.1:8080
ListenSocket string `yaml:"listen_socket,omitempty"`
TLS *TLSCfg `yaml:"tls"`
DbConfig *DatabaseCfg `yaml:"-"`
LogDir string `yaml:"-"`
LogMedia string `yaml:"-"`
OnlineClient *OnlineApiClientCfg `yaml:"online_client"`
ProfilesPath string `yaml:"profiles_path,omitempty"`
ConsoleConfigPath string `yaml:"console_path,omitempty"`
ConsoleConfig *ConsoleConfig `yaml:"-"`
Profiles []*ProfileCfg `yaml:"-"`
LogLevel *log.Level `yaml:"log_level"`
UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"`
TrustedProxies *[]string `yaml:"trusted_proxies,omitempty"`
CompressLogs *bool `yaml:"-"`
LogMaxSize int `yaml:"-"`
LogMaxAge int `yaml:"-"`
LogMaxFiles int `yaml:"-"`
LogFormat string `yaml:"-"`
TrustedIPs []string `yaml:"trusted_ips,omitempty"`
PapiLogLevel *log.Level `yaml:"papi_log_level"`
DisableRemoteLapiRegistration bool `yaml:"disable_remote_lapi_registration,omitempty"`
CapiWhitelistsPath string `yaml:"capi_whitelists_path,omitempty"`
CapiWhitelists *CapiWhitelist `yaml:"-"`
AutoRegister *LocalAPIAutoRegisterCfg `yaml:"auto_registration,omitempty"`
}

func (c *LocalApiServerCfg) ClientURL() string {
if c == nil {
return ""
Expand Down

0 comments on commit 5348591

Please sign in to comment.