mirror of
https://github.com/therootcompany/golib.git
synced 2026-04-24 20:58:00 +00:00
refactor(formmailer): use *dataset.View directly, tighter timeouts
- Drop CohortSource interface — it had exactly one implementation. Blacklist is now *dataset.View[ipcohort.Cohort] directly, matching check-ip's usage. One concrete type, no premature abstraction. - SMTP 15s → 5s, MX 3s → 2s. A relay or resolver that isn't responding inside those bounds isn't going to deliver the mail; faster failure is better than holding the request goroutine.
This commit is contained in:
parent
b23610fdf1
commit
f972d6f117
@ -43,6 +43,7 @@ import (
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/therootcompany/golib/net/ipcohort"
|
||||
"github.com/therootcompany/golib/sync/dataset"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -55,8 +56,8 @@ const (
|
||||
|
||||
defaultRPM = 5
|
||||
defaultBurst = 3
|
||||
defaultSMTPTimeout = 15 * time.Second
|
||||
defaultMXTimeout = 3 * time.Second
|
||||
defaultSMTPTimeout = 5 * time.Second
|
||||
defaultMXTimeout = 2 * time.Second
|
||||
|
||||
limiterTTL = 10 * time.Minute
|
||||
limiterSweepEvery = 1024 // sweep once every N handler invocations
|
||||
@ -72,12 +73,6 @@ var (
|
||||
phoneRe = regexp.MustCompile(`^[0-9+\-\(\) ]{7,20}$`)
|
||||
)
|
||||
|
||||
// CohortSource returns the current cohort snapshot, or nil if not yet loaded.
|
||||
// *dataset.View[ipcohort.Cohort] satisfies this interface directly.
|
||||
type CohortSource interface {
|
||||
Value() *ipcohort.Cohort
|
||||
}
|
||||
|
||||
// FormFields maps logical field names to the HTML form field names.
|
||||
// Zero values use GravityForms-compatible defaults (input_1, input_3, etc.).
|
||||
type FormFields struct {
|
||||
@ -119,8 +114,8 @@ type FormMailer struct {
|
||||
ContentType string // inferred from SuccessBody if empty
|
||||
|
||||
// Blacklist — if set, matching IPs are rejected before any other processing.
|
||||
// *dataset.View[ipcohort.Cohort] satisfies this interface.
|
||||
Blacklist CohortSource
|
||||
// Value() returns nil before the first successful load (no blocks applied).
|
||||
Blacklist *dataset.View[ipcohort.Cohort]
|
||||
|
||||
// AllowedCountries — if non-nil, only requests from listed ISO codes are
|
||||
// accepted. Unknown country ("") is always allowed.
|
||||
|
||||
@ -5,5 +5,6 @@ go 1.26.0
|
||||
require (
|
||||
github.com/phuslu/iploc v1.0.20260415
|
||||
github.com/therootcompany/golib/net/ipcohort v0.0.0
|
||||
github.com/therootcompany/golib/sync/dataset v0.0.0
|
||||
golang.org/x/time v0.15.0
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user