Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 64 additions & 46 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
version = '2'

[run]
concurrency = 4
tests = false
concurrency = 4
tests = false

[linters]
default = 'none'
enable = [
'errcheck',
'exhaustive',
'goconst',
'gocritic',
'gosec',
'govet',
'ineffassign',
'misspell',
'prealloc',
'staticcheck',
'unconvert',
'unparam',
'unused'
]

[[issues.exclude-rules]]
linters = ["misspell"]
source = "cancelled"
[linters.settings]
[linters.settings.exhaustive]
default-signifies-exhaustive = true

[linters-settings]
[linters-settings.gocognit]
min-complexity = 12
[linters.settings.gocognit]
min-complexity = 12

[linters-settings.gofumpt]
lang-version = "1.20"
extra-rules = true
[linters.settings.goconst]
min-len = 3
min-occurrences = 2

[linters-settings.goconst]
min-len = 2
min-occurrences = 2
[linters.settings.misspell]
locale = 'US'

[linters-settings.misspell]
locale = "US"
[linters.exclusions]
generated = 'lax'
presets = [
'comments',
'common-false-positives',
'legacy',
'std-error-handling'
]
paths = [
'third_party$',
'builtin$',
'examples$'
]

[linters-settings.errcheck]
ignore = "fmt:.*,github.com/go-kit/kit/log:^Log$"
[[linters.exclusions.rules]]
linters = [
'misspell'
]
source = 'cancelled'

[linters-settings.exhaustive]
default-signifies-exhaustive = true
[formatters]
enable = [
'gofumpt'
]

[linters]
[formatters.settings]
[formatters.settings.gofumpt]
extra-rules = true

# Allow-listing, to be more CI safe.
disable-all = true

# @see https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable = [
"staticcheck",
"gosimple",
"ineffassign",
"typecheck",
"govet",
"errcheck",
"unused",
"exhaustive",
"stylecheck",
"gosec",
"unconvert",
"goconst",
"depguard",
"misspell",
"unparam",
"prealloc",
"gofumpt",
"exportloopref",
"gocritic",
]
[formatters.exclusions]
generated = 'lax'
paths = [
'third_party$',
'builtin$',
'examples$'
]
6 changes: 3 additions & 3 deletions cmd/eri-cli/commands/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ func init() {

// Disabled for now, since foo\nbar\n parses fine in the liberal CSV parser.
// checkCmd.Flags().StringVar(&checkSettings.Format, "format", inputFormatCSV, "Format to read. CSV works also for unquoted emails separated with a '\\n'")
checkCmd.Flags().Uint64Var(&checkSettings.CSV.skipRows, "csv-skip-rows", 0, "Rows to skip, useful when wanting to skip the header in CSV files")
checkCmd.Flags().Uint64Var(&checkSettings.CSV.column, "csv-column", 0, "The column to read email addresses from, 0-indexed")
checkCmd.Flags().Uint32Var(&checkSettings.CSV.skipRows, "csv-skip-rows", 0, "Rows to skip, useful when wanting to skip the header in CSV files")
checkCmd.Flags().Uint32Var(&checkSettings.CSV.column, "csv-column", 0, "The column to read email addresses from, 0-indexed")
checkCmd.Flags().IPVar(&checkSettings.Check.Resolver, "resolver", nil, "Custom DNS resolver IP (e.g.: 1.1.1.1) to use, otherwise system default is used")
checkCmd.Flags().DurationVar(&checkSettings.Check.TTL, "ttl", 30*time.Second, "Max duration per check, e.g.: '2s' or '100ms'. When exceeded, a check is considered invalid")
checkCmd.Flags().BoolVar(&checkSettings.Check.InputIsEmailAddress, "input-is-email", false, "If the input isn't an e-mail address, don't fall back on domain only checks")
checkCmd.Flags().Uint64Var(&checkSettings.Workers, "workers", 50, "The number of concurrent workers to use when in piped mode (1-1024)")
checkCmd.Flags().Uint32Var(&checkSettings.Workers, "workers", 50, "The number of concurrent workers to use when in piped mode (1-1024)")
}
4 changes: 2 additions & 2 deletions cmd/eri-cli/commands/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func createCSVIterator(r io.Reader) *iterator.CallbackIterator {
if eof || err == io.EOF {
eof = true

if uint64(len(record)) > checkSettings.CSV.column {
if len(record) > int(checkSettings.CSV.column) {
value = record[checkSettings.CSV.column]
}

Expand All @@ -66,7 +66,7 @@ func createCSVIterator(r io.Reader) *iterator.CallbackIterator {
return "", err
}

if uint64(len(record)) > checkSettings.CSV.column {
if len(record) > int(checkSettings.CSV.column) {
value = record[checkSettings.CSV.column]
}

Expand Down
1 change: 1 addition & 0 deletions cmd/eri-cli/commands/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var reportCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(reportCmd)

//nolint:goconst
reportCmd.Flags().StringVar(&reportSettings.Format, "format", outputFormatJSON, "The format in which to report in, supported id: '"+outputFormatText+"' or '"+outputFormatJSON+"'")
reportCmd.Flags().BoolVar(&reportSettings.OnlyInvalid, "only-invalid", false, "Only report rejected checks (ignored when report is stats)")
reportCmd.Flags().StringVar(&reportSettings.Details, "details", string(RFFull), "Type of report, supported is: '"+string(RFStats)+"' or '"+string(RFFull)+"'")
Expand Down
6 changes: 3 additions & 3 deletions cmd/eri-cli/commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type CheckSettings struct {
Format string
CSV csvOptions
Check checkOptions
Workers uint64
Workers uint32
}

type checkOptions struct {
Expand All @@ -62,6 +62,6 @@ type checkOptions struct {
}

type csvOptions struct {
skipRows uint64
column uint64
skipRows uint32
column uint32
}
16 changes: 8 additions & 8 deletions cmd/web/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func NewConfig(fileName string) (Config, error) {
type Config struct {
Server struct {
ListenOn string `toml:"listenOn"`
ConnectionLimit uint `toml:"connectionLimit"`
ConnectionLimit uint32 `toml:"connectionLimit"`
InstanceID string `toml:"-"` // Extra identifier used in logs and for instance identification
MaxRequestSize uint64 `toml:"maxRequestSize" usage:"Maximum amount of bytes until a HTTP request is accepted"`
MaxRequestSize uint32 `toml:"maxRequestSize" usage:"Maximum amount of bytes until a HTTP request is accepted"`
NetTTL Duration `toml:"netTTL" usage:"Max time to spend on external communication"`
PathStrip string `toml:"pathStrip"`
Headers Headers `toml:"headers" env:"-" usage:"Only (repeatable) flag or config file supported"`
Expand Down Expand Up @@ -75,8 +75,8 @@ type Config struct {
} `toml:"validator" flag:",inline" env:",inline"`
Services struct {
Autocomplete struct {
RecipientThreshold uint64 `toml:"recipientThreshold" usage:"Define the minimum amount of recipients a domain needs before allowed in the autocomplete"`
MaxSuggestions uint64 `toml:"maxSuggestions" usage:"The maximum number of suggestions to return"`
RecipientThreshold uint32 `toml:"recipientThreshold" usage:"Define the minimum amount of recipients a domain needs before allowed in the autocomplete"`
MaxSuggestions uint32 `toml:"maxSuggestions" usage:"The maximum number of suggestions to return"`
} `toml:"autocomplete"`
Suggest struct {
Prefer Preferred `toml:"prefer" env:"-" usage:"A repeatable flag to create a preference list for common alternatives, example.com=example.org"`
Expand All @@ -85,17 +85,17 @@ type Config struct {
Backend struct {
Driver string `toml:"driver" usage:"List a driver to use, currently supporting: 'memory' or 'postgres'"`
URL string `toml:"url"`
MaxConnections uint `toml:"maxConnections"`
MaxIdleConnections uint `toml:"maxIdleConnections"`
MaxConnections uint16 `toml:"maxConnections"`
MaxIdleConnections uint16 `toml:"maxIdleConnections"`
} `toml:"backend"`
GraphQL struct {
PrettyOutput bool `toml:"prettyOutput" flag:"pretty" env:"PRETTY"`
GraphiQL bool `toml:"graphiQL" flag:"graphiql" env:"GRAPHIQL"`
Playground bool `toml:"playground"`
} `toml:"graphql" flag:"graphql" env:"GRAPHQL"`
RateLimiter struct {
Rate int64 `toml:"rate"`
Capacity int64 `toml:"capacity"`
Rate int32 `toml:"rate"`
Capacity int32 `toml:"capacity"`
ParkedTTL Duration `toml:"parkedTTL" flag:"parked-ttl"`
} `toml:"rateLimiter"`
GCP struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (

type marshalFn func(v interface{}) ([]byte, error)

func NewAutoCompleteHandler(logger logrus.FieldLogger, svc *services.AutocompleteSvc, maxSuggestions, maxBodySize uint64, jsonMarshaller marshalFn) http.HandlerFunc {
func NewAutoCompleteHandler(logger logrus.FieldLogger, svc *services.AutocompleteSvc, maxSuggestions, maxBodySize uint32, jsonMarshaller marshalFn) http.HandlerFunc {
if jsonMarshaller == nil {
jsonMarshaller = json.Marshal
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func NewAutoCompleteHandler(logger logrus.FieldLogger, svc *services.Autocomplet
}

// NewSuggestHandler constructs an HTTP handler that deals with suggestion requests
func NewSuggestHandler(logger logrus.FieldLogger, svc *services.SuggestSvc, maxBodySize uint64, jsonMarshaller marshalFn) http.HandlerFunc {
func NewSuggestHandler(logger logrus.FieldLogger, svc *services.SuggestSvc, maxBodySize uint32, jsonMarshaller marshalFn) http.HandlerFunc {
if jsonMarshaller == nil {
jsonMarshaller = json.Marshal
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/web/hitlist/hitlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (hl *HitList) Has(parts types.EmailParts) (domain, local bool) {
var hit Hit

if parts.Domain == "" {
return
return domain, local
}

inputDomain := Domain(strings.ToLower(parts.Domain))
Expand All @@ -65,7 +65,7 @@ func (hl *HitList) Has(parts types.EmailParts) (domain, local bool) {

if hit, domain = hl.hits[inputDomain]; domain {
if parts.Local == "" {
return
return domain, local
}

inputLocal := strings.ToLower(parts.Local)
Expand All @@ -74,7 +74,7 @@ func (hl *HitList) Has(parts types.EmailParts) (domain, local bool) {
_, local = hit.Recipients[recipient]
}

return
return domain, local
}

// CreateInternalTypes returns the Recipient and Domain types for an Email Type Parts. It's stateless, and solely
Expand All @@ -84,12 +84,12 @@ func (hl *HitList) CreateInternalTypes(p types.EmailParts) (domain Domain, recip
if len(p.Domain) == 0 || len(p.Local) == 0 {
recipient = Recipient("")
err = ErrInvalidSyntax
return
return domain, recipient, err
}

domain = Domain(strings.ToLower(p.Domain))
recipient = hl.h.Sum([]byte(strings.ToLower(p.Local)))
return
return domain, recipient, err
}

func (hl *HitList) GetDomainValidationDetails(d Domain) (validator.Details, bool) {
Expand Down Expand Up @@ -124,7 +124,7 @@ func (hl *HitList) GetRecipientCount(d Domain) (amount uint64) {
}
hl.lock.RUnlock()

return
return amount
}

// AddInternalParts adds values considered "safe". Typically you would only use this on provisioning HitList from a storage layer
Expand Down
3 changes: 1 addition & 2 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func main() {

var pubSubSvc *gcp.PubSubSvc
pubSubSvc, err = createPubSubSvc(conf, logger, rtPubSub, hitList, myFinder)

if err != nil {
logger.WithError(err).Error("Unable to create the pub/sub client")
exitCode = ErrExUnavailable
Expand Down Expand Up @@ -160,7 +159,7 @@ func main() {

var bucket handlers.TakeMaxDuration
if conf.RateLimiter.Rate > 0 && conf.RateLimiter.Capacity > 0 {
bucket = ratelimit.NewBucketWithRate(float64(conf.RateLimiter.Rate), conf.RateLimiter.Capacity)
bucket = ratelimit.NewBucketWithRate(float64(conf.RateLimiter.Rate), int64(conf.RateLimiter.Capacity))
}

ct := cors.New(cors.Options{
Expand Down
4 changes: 2 additions & 2 deletions cmd/web/persist/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func rowToInternalParts(row hitListRow) (hitlist.Domain, hitlist.Recipient) {
type hitListRow struct {
Domain string `sql:"domain"`
Recipient []byte `sql:"recipient"`
Validations int64 `sql:"validations"`
Steps int64 `sql:"steps"`
Validations uint8 `sql:"validations"`
Steps uint8 `sql:"steps"`
}

func deferClose(toClose io.Closer, log logrus.FieldLogger) {
Expand Down
10 changes: 5 additions & 5 deletions cmd/web/services/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ var (
ErrInputTooLong = errors.New("input is too long")
)

func NewAutocompleteService(f *finder.Finder, hitList *hitlist.HitList, recipientThreshold uint64, logger logrus.FieldLogger) *AutocompleteSvc {
func NewAutocompleteService(f *finder.Finder, hitList *hitlist.HitList, recipientThreshold uint32, logger logrus.FieldLogger) *AutocompleteSvc {
return &AutocompleteSvc{
finder: f,
logger: logger,
hitList: hitList,
recipientThreshold: recipientThreshold,
recipientThreshold: uint64(recipientThreshold),
}
}

Expand All @@ -34,7 +34,7 @@ type AutocompleteResult struct {
Suggestions []string
}

func (a *AutocompleteSvc) Autocomplete(ctx context.Context, domain string, limit uint64) (AutocompleteResult, error) {
func (a *AutocompleteSvc) Autocomplete(ctx context.Context, domain string, limit uint32) (AutocompleteResult, error) {
if domain == "" {
return AutocompleteResult{}, ErrEmptyInput
}
Expand All @@ -59,7 +59,7 @@ func (a *AutocompleteSvc) Autocomplete(ctx context.Context, domain string, limit
}, nil
}

func (a *AutocompleteSvc) filter(ctx context.Context, list []string, limit uint64) (filteredList []string, err error) {
func (a *AutocompleteSvc) filter(ctx context.Context, list []string, limit uint32) (filteredList []string, err error) {
filteredList = make([]string, 0, limit)
for _, domain := range list {
if ctx.Err() != nil {
Expand All @@ -75,5 +75,5 @@ func (a *AutocompleteSvc) filter(ctx context.Context, list []string, limit uint6
}
}

return
return filteredList, err
}
8 changes: 4 additions & 4 deletions cmd/web/services/autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestAutocompleteSvc_Autocomplete(t *testing.T) {
})

type fields struct {
recipientThreshold uint64
recipientThreshold uint32
}

type args struct {
ctx context.Context
domain string
limit uint64
limit uint32
}
tests := []struct {
name string
Expand Down Expand Up @@ -214,12 +214,12 @@ func TestAutocompleteSvc_filter(t *testing.T) {
finder *finder.Finder
logger logrus.FieldLogger
hitList *hitlist.HitList
recipientThreshold uint64
recipientThreshold uint32
}
type args struct {
ctx context.Context
list []string
limit uint64
limit uint32
}
tests := []struct {
name string
Expand Down
Loading