Documentation
¶
Overview ¶
Package gate decides what a reader of the publication website may read (design expansion phase 7, brief §3.3): a post's or a page's visibility (Public, Members, Paid for every tier or chosen tiers), the meter (N free posts per calendar month for visitors and for free members) and "Never free". It is pure: the website package reads the reader, the rules and the meter's state and records the reads; the pages of later phases call Page (pages aren't metered).
Gating happens on the server. A reader without access gets the preview (the post down to its free preview marker, or its title, cover and excerpt) and the paywall card: the rest is never sent, so it can't be shown by removing a style, and feeds, the sitemap and search see what an anonymous visitor sees.
Index ¶
Constants ¶
const ( Public = "public" Members = "members" Paid = "paid" )
Visibility levels.
const ( RuleVisitor = "visitor" RuleMember = "member" )
Meter rules.
Variables ¶
This section is empty.
Functions ¶
func MeterRule ¶
func MeterRule(v Visibility, r Reader, rules Rules) string
MeterRule is the meter rule that applies to a reader on a post ("" for none: a public post, a member on a members-only post, a paid member).
func ValidLevel ¶
ValidLevel reports whether level is a visibility.
Types ¶
type Decision ¶
type Decision struct {
Access Access
Reason Reason
// Rule, Used and Limit describe the meter when it applies: "This is 1
// of 2 members-only posts you can read this month without signing in".
Rule string
Used int
Limit int
// Count asks the caller to record the read (the first read this month).
Count bool
// Tier is the member's tier that opened a paid post (the quiet label).
Tier *Tier
// FreeRow says the paywall card may offer a free sign-up: the meter
// lets free members read paid posts, or the visitor meter is on.
FreeRow bool
}
Decision is what a reader gets of one post.
func Decide ¶
func Decide(v Visibility, r Reader, rules Rules, m MeterState) Decision
Decide decides a post for a reader. m is the reader's meter state under the rule that applies (MeterRule).
type Member ¶
type Member struct {
ContactID uuid.UUID
Email string
Name string
// Tiers are the paid tiers the member holds now (trialing, active, past
// due with access, complimentary or a gift).
Tiers []Tier
}
Member is a signed-in reader.
type MeterState ¶
MeterState is a reader's month under one rule: how many posts were counted, and whether this post is one of them (reading it again is free).
type Reader ¶
type Reader struct {
Member *Member
// Browser is a visitor's meter key: the hash of the first-party meter
// cookie ("" until the browser has one).
Browser string
}
Reader is who is reading: a signed-in member, or a visitor.
type Reason ¶
type Reason string
Reason says why.
const ( ReasonPublic Reason = "public" // ReasonMember: a members-only post read by a member. ReasonMember Reason = "member" // ReasonTier: a paid post read by a member holding a tier that can read it. ReasonTier Reason = "tier" // ReasonMetered: a free read the meter counts now (the first time this month). ReasonMetered Reason = "metered" // ReasonReread: a post the meter already counted this month; free again. ReasonReread Reason = "reread" // ReasonSignin: a visitor on a members-only post without a meter read left // (or with the meter off or the post never free): sign in or sign up. ReasonSignin Reason = "signin" // ReasonSignupMeter: a visitor who used up the visitor meter: "Sign up // free to keep reading". ReasonSignupMeter Reason = "signup_meter" // ReasonUpgrade: a paid post for a visitor or a member without the tier. ReasonUpgrade Reason = "upgrade" // ReasonUpgradeMeter: a free member who used up the member meter. ReasonUpgradeMeter Reason = "upgrade_meter" // ReasonSigninOff: sign-in is turned off; members-only and paid posts // can't be read on the web. ReasonSigninOff Reason = "signin_off" )
type Rules ¶
type Rules struct {
// SigninOn is "Members can sign in". Off, members-only and paid posts
// can't be read on the web by anyone.
SigninOn bool
// The meter: visitors who aren't signed in can read Visitors
// members-only posts a month; free members can read Members paid posts
// a month.
VisitorsOn bool
Visitors int
MembersOn bool
Members int
// Tiers are every paid tier, by id, for comparing ranks.
Tiers map[uuid.UUID]Tier
}
Rules are the website's access settings.
type Tier ¶
type Tier struct {
ID uuid.UUID
// Name is the tier's name ("Weekly Digest Insider"); Label the quiet
// label on posts ("Insider").
Name string
Label string
Rank int
}
Tier is a paid tier. A higher rank includes the paid content of lower ranks ("Founding member includes everything in Insider").
func Qualifies ¶
Qualifies returns the held tier that can read a Paid post, or nil. Any tier reads a post for every tier; for chosen tiers, a chosen one or a tier ranked above one of them (a higher tier includes a lower tier's paid content).
func Readers ¶
func Readers(v Visibility, all []Tier) []Tier
Readers are the tiers that can read a Paid post, from every tier: the paywall card offers only these.