Documentation
¶
Overview ¶
Package agegate defines the pluggable age-determination provider used to support COPPA-style age-gating at signup. A deployment that leaves age-gating disabled gets the no-op provider, which classifies everyone as an adult and never flags a minor — so signup behaves exactly as it did before this package existed.
The interface is intentionally narrow: it maps a date of birth to an AgeBand (and the derived minor flag) given a reference instant ("now"). The derived band/minor status are NOT persisted; they are recomputed from the stored date of birth and the deployment's configured threshold, so the threshold can change without a data backfill.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgeBand ¶
type AgeBand string
AgeBand is the coarse age classification derived from a date of birth.
const ( // BandUnknown is returned when no date of birth is available (the // zero-value / un-collected case). The service treats an unknown band // as non-minor. BandUnknown AgeBand = "" // BandChild is a user at or below the configured child-max age (the // COPPA-protected band). BandChild AgeBand = "CHILD" // BandTeen is a user above the child-max age but still a minor (below // the adult age). BandTeen AgeBand = "TEEN" // BandAdult is a user at or above the adult age. BandAdult AgeBand = "ADULT" )
type Decision ¶
type Decision struct {
Band AgeBand
IsMinor bool
// HasDOB is false when no usable date of birth was supplied, in which
// case Band is BandUnknown and IsMinor is false.
HasDOB bool
}
Decision is the result of classifying a date of birth.
type Determiner ¶
type Determiner interface {
// Name returns the provider identifier ("noop" or "threshold").
Name() string
// Enabled reports whether age-gating is active. When false the service
// skips all age-band derivation and consent gating.
Enabled() bool
// Determine classifies dobMs (date of birth as epoch milliseconds; 0 =
// unknown) relative to now. A zero or future dobMs yields BandUnknown /
// HasDOB=false.
Determine(dobMs int64, now time.Time) Decision
}
Determiner classifies a date of birth into an AgeBand. The service holds exactly one Determiner for the lifetime of the process.
type NoopDeterminer ¶
type NoopDeterminer struct{}
NoopDeterminer is the default provider used when age-gating is disabled. It classifies everyone as an adult and never reports a minor, so signup and token issuance behave exactly as they did before age-gating existed.
func NewNoop ¶
func NewNoop() *NoopDeterminer
NewNoop returns the disabled, everyone-is-an-adult provider.
func (NoopDeterminer) Determine ¶
func (NoopDeterminer) Determine(int64, time.Time) Decision
Determine implements Determiner; always returns the adult, non-minor, no-DOB decision regardless of the supplied date of birth.
func (NoopDeterminer) Enabled ¶
func (NoopDeterminer) Enabled() bool
Enabled implements Determiner; always false.
type ThresholdDeterminer ¶
type ThresholdDeterminer struct {
// contains filtered or unexported fields
}
ThresholdDeterminer classifies a date of birth using two configured age boundaries:
- childMaxAge: a user whose age is <= childMaxAge is in BandChild (the COPPA-protected band). 12 is the conventional value (under-13).
- adultAge: a user whose age is >= adultAge is in BandAdult. A user between childMaxAge and adultAge is in BandTeen.
IsMinor is true for any user below adultAge (CHILD or TEEN).
func NewThreshold ¶
func NewThreshold(childMaxAge, adultAge int) (*ThresholdDeterminer, error)
NewThreshold builds the enabled, threshold-based provider. It validates the invariant 0 <= childMaxAge < adultAge so a misconfiguration is caught at startup rather than silently classifying every user as a child.
func (ThresholdDeterminer) Determine ¶
func (d ThresholdDeterminer) Determine(dobMs int64, now time.Time) Decision
Determine implements Determiner. A zero or future dobMs yields an unknown, non-minor decision (HasDOB=false).
func (ThresholdDeterminer) Enabled ¶
func (ThresholdDeterminer) Enabled() bool
Enabled implements Determiner; always true.
func (ThresholdDeterminer) Name ¶
func (ThresholdDeterminer) Name() string
Name implements Determiner.