Skip to content

Commit

Permalink
Enable gocyclo, lll, maintidx, and make them happy (arriven#393)
Browse files Browse the repository at this point in the history
* Enable gocyclo, lll, maintidx, and make them happy

* Make new gofumpt happy
  • Loading branch information
jdoe7865623 authored Mar 22, 2022
1 parent b2b86e6 commit 06d290b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
27 changes: 12 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -914,14 +914,14 @@ linters-settings:
# reject:
# - github.com\/user\/package\/v4\.Type

# lll:
# # Max line length, lines longer will be reported.
# # '\t' is counted as 1 character by default, and can be changed with the tab-width option.
# # Default: 120.
# line-length: 120
# # Tab width in spaces.
# # Default: 1
# tab-width: 1
lll:
# Max line length, lines longer will be reported.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
# Default: 120.
line-length: 160
# Tab width in spaces.
# Default: 1
tab-width: 4

# maintidx:
# # Show functions with maintainability index lower than N.
Expand Down Expand Up @@ -1659,7 +1659,7 @@ linters:
- gocognit
- goconst
- gocritic
# - gocyclo
- gocyclo
# - godot
# - godox
# - goerr113
Expand All @@ -1681,8 +1681,8 @@ linters:
- ineffassign
# - interfacer # deprecated
# - ireturn
# - lll
# - maintidx
- lll
- maintidx
- makezero
# - maligned # deprecated
- misspell
Expand Down Expand Up @@ -1757,10 +1757,7 @@ linters:
# # Exclude some linters from running on tests files.
# - path: _test\.go
# linters:
# - gocyclo
# - errcheck
# - dupl
# - gosec
# - funlen

# # Exclude known linters from partially hard-vendored code,
# # which is impossible to exclude via `nolint` comments.
Expand Down
44 changes: 30 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,50 @@ func main() {
log.Printf("DB1000n [Version: %s][PID=%d]\n", ota.Version, os.Getpid())

// Config
configPaths := flag.String("c", utils.GetEnvStringDefault("CONFIG", "https://raw.githubusercontent.com/db1000n-coordinators/LoadTestConfig/main/config.v0.7.json"), "path to config files, separated by a comma, each path can be a web endpoint")
configPaths := flag.String("c",
utils.GetEnvStringDefault("CONFIG", "https://raw.githubusercontent.com/db1000n-coordinators/LoadTestConfig/main/config.v0.7.json"),
"path to config files, separated by a comma, each path can be a web endpoint")
backupConfig := flag.String("b", config.DefaultConfig, "raw backup config in case the primary one is unavailable")
configFormat := flag.String("format", utils.GetEnvStringDefault("CONFIG_FORMAT", "yaml"), "config format")
refreshTimeout := flag.Duration("refresh-interval", utils.GetEnvDurationDefault("REFRESH_INTERVAL", time.Minute), "refresh timeout for updating the config")
refreshTimeout := flag.Duration("refresh-interval", utils.GetEnvDurationDefault("REFRESH_INTERVAL", time.Minute),
"refresh timeout for updating the config")

// Proxying
systemProxy := flag.String("proxy", utils.GetEnvStringDefault("SYSTEM_PROXY", ""), "system proxy to set by default (can be a comma-separated list or a template)")
systemProxy := flag.String("proxy", utils.GetEnvStringDefault("SYSTEM_PROXY", ""),
"system proxy to set by default (can be a comma-separated list or a template)")

// Jobs
scaleFactor := flag.Int("scale", utils.GetEnvIntDefault("SCALE_FACTOR", 1), "used to scale the amount of jobs being launched, effect is similar to launching multiple instances at once")
skipEncrytedJobs := flag.Bool("skip-encrypted", utils.GetEnvBoolDefault("SKIP_ENCRYPTED", false), "set to true if you want to only run plaintext jobs from the config for security considerations")
enablePrimitiveJobs := flag.Bool("enable-primitive", utils.GetEnvBoolDefault("ENABLE_PRIMITIVE", true), "set to true if you want to run primitive jobs that are less resource-efficient")
scaleFactor := flag.Int("scale", utils.GetEnvIntDefault("SCALE_FACTOR", 1),
"used to scale the amount of jobs being launched, effect is similar to launching multiple instances at once")
skipEncrytedJobs := flag.Bool("skip-encrypted", utils.GetEnvBoolDefault("SKIP_ENCRYPTED", false),
"set to true if you want to only run plaintext jobs from the config for security considerations")
enablePrimitiveJobs := flag.Bool("enable-primitive", utils.GetEnvBoolDefault("ENABLE_PRIMITIVE", true),
"set to true if you want to run primitive jobs that are less resource-efficient")

// Prometheus
prometheusOn := flag.Bool("prometheus_on", utils.GetEnvBoolDefault("PROMETHEUS_ON", true), "Start metrics exporting via HTTP and pushing to gateways (specified via <prometheus_gateways>)")
prometheusPushGateways := flag.String("prometheus_gateways", utils.GetEnvStringDefault("PROMETHEUS_GATEWAYS", "https://178.62.78.144:9091,https://46.101.26.43:9091,https://178.62.33.149:9091"), "Comma separated list of prometheus push gateways")
prometheusOn := flag.Bool("prometheus_on", utils.GetEnvBoolDefault("PROMETHEUS_ON", true),
"Start metrics exporting via HTTP and pushing to gateways (specified via <prometheus_gateways>)")
prometheusPushGateways := flag.String("prometheus_gateways",
utils.GetEnvStringDefault("PROMETHEUS_GATEWAYS", "https://178.62.78.144:9091,https://46.101.26.43:9091,https://178.62.33.149:9091"),
"Comma separated list of prometheus push gateways")

// Auto-update
doAutoUpdate := flag.Bool("enable-self-update", utils.GetEnvBoolDefault("ENABLE_SELF_UPDATE", false), "Enable the application automatic updates on the startup")
doRestartOnUpdate := flag.Bool("restart-on-update", utils.GetEnvBoolDefault("RESTART_ON_UPDATE", true), "Allows application to restart upon successful update (ignored if auto-update is disabled)")
skipUpdateCheckOnStart := flag.Bool("skip-update-check-on-start", utils.GetEnvBoolDefault("SKIP_UPDATE_CHECK_ON_START", false), "Allows to skip the update check at the startup (usually set automatically by the previous version)")
autoUpdateCheckFrequency := flag.Duration("self-update-check-frequency", utils.GetEnvDurationDefault("SELF_UPDATE_CHECK_FREQUENCY", defaultUpdateCheckFrequency), "How often to run auto-update checks")
doAutoUpdate := flag.Bool("enable-self-update", utils.GetEnvBoolDefault("ENABLE_SELF_UPDATE", false),
"Enable the application automatic updates on the startup")
doRestartOnUpdate := flag.Bool("restart-on-update", utils.GetEnvBoolDefault("RESTART_ON_UPDATE", true),
"Allows application to restart upon successful update (ignored if auto-update is disabled)")
skipUpdateCheckOnStart := flag.Bool("skip-update-check-on-start", utils.GetEnvBoolDefault("SKIP_UPDATE_CHECK_ON_START", false),
"Allows to skip the update check at the startup (usually set automatically by the previous version)")
autoUpdateCheckFrequency := flag.Duration("self-update-check-frequency",
utils.GetEnvDurationDefault("SELF_UPDATE_CHECK_FREQUENCY", defaultUpdateCheckFrequency), "How often to run auto-update checks")
updaterMode := flag.Bool("updater-mode", utils.GetEnvBoolDefault("UPDATER_MODE", false), "Only run config updater")
destinationConfig := flag.String("updater-destination-config", utils.GetEnvStringDefault("UPDATER_DESTINATION_CONFIG", "config/config.json"), "Destination config file to write (only applies if updater-mode is enabled")
destinationConfig := flag.String("updater-destination-config", utils.GetEnvStringDefault("UPDATER_DESTINATION_CONFIG", "config/config.json"),
"Destination config file to write (only applies if updater-mode is enabled")

// Country check
countryList := flag.String("country-list", utils.GetEnvStringDefault("COUNTRY_LIST", "Ukraine"), "comma-separated list of countries")
strictCountryCheck := flag.Bool("strict-country-check", utils.GetEnvBoolDefault("STRICT_COUNTRY_CHECK", false), "enable strict country check; will also exit if IP can't be determined")
strictCountryCheck := flag.Bool("strict-country-check", utils.GetEnvBoolDefault("STRICT_COUNTRY_CHECK", false),
"enable strict country check; will also exit if IP can't be determined")

// Misc
debug := flag.Bool("debug", utils.GetEnvBoolDefault("DEBUG", false), "enable debug level logging")
Expand Down
6 changes: 3 additions & 3 deletions src/core/dnsblast/qry/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package qry

import "github.com/miekg/dns"

// ResponseCode convert numerical response code value to string
// ResponseCode converts numerical response code value to string.
func ResponseCode(rc int) string {
rcodes := map[int]string{
0: "NOERROR",
Expand All @@ -21,8 +21,8 @@ func ResponseCode(rc int) string {
return rcodes[rc]
}

// Qtype is used to conver string representation of query type into proper dns format
//nolint:cyclop // The string map alternative is orders of magnitude slower
// Qtype converts string representation of query type into a proper DNS format.
//nolint:cyclop,gocyclo,maintidx // The string map alternative is orders of magnitude slower
func Qtype(qt string) uint16 {
switch qt {
case "None":
Expand Down
8 changes: 6 additions & 2 deletions src/core/slowloris/slowloris.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func Start(stopChan chan bool, logger *zap.Logger, config *Config) error {
return nil
}

func (s SlowLoris) dialWorker(stopChan chan bool, logger *zap.Logger, config *Config, activeConnectionsCh chan<- int, targetHostPort string, targetURI *url.URL, requestHeader []byte) {
func (s SlowLoris) dialWorker(stopChan chan bool, logger *zap.Logger, config *Config, activeConnectionsCh chan<- int,
targetHostPort string, targetURI *url.URL, requestHeader []byte,
) {
isTLS := targetURI.Scheme == "https"

for {
Expand Down Expand Up @@ -169,7 +171,9 @@ func (s SlowLoris) dialVictim(logger *zap.Logger, config *Config, hostPort strin
return tlsConn
}

func (s SlowLoris) doLoris(logger *zap.Logger, config *Config, destinationHostPort string, conn io.ReadWriteCloser, activeConnectionsCh chan<- int, requestHeader []byte) {
func (s SlowLoris) doLoris(logger *zap.Logger, config *Config, destinationHostPort string, conn io.ReadWriteCloser,
activeConnectionsCh chan<- int, requestHeader []byte,
) {
defer conn.Close()

if _, err := conn.Write(requestHeader); err != nil {
Expand Down
Loading

0 comments on commit 06d290b

Please sign in to comment.