Documentation
¶
Overview ¶
Package pages holds the privacy-friendly analytics view for static sites.
Package pages holds the build log and dependency cache rules for git-connected Pages builds.
Package pages converts existing static hosting config files into the _redirects and _headers formats. It is pure local text conversion.
Package pages holds Pages logic that does not belong to a single HTTP route.
Package pages holds the named performance presets for static sites.
Index ¶
- Constants
- Variables
- func Apply(rs *spec.StaticRuleset, id string, l spec.StaticLimits) error
- func CacheDir(root, site string) (string, error)
- func CacheKey(lockfiles ...[]byte) string
- func EvictOldest(siteDir, keep string, limit int64) error
- func LogExpired(finished, now time.Time, retention time.Duration) bool
- func ParseEvents(events []string) (onSuccess, onFailure bool, err error)
- func RangeFits(span time.Duration, retentionDays int) bool
- func RefHost(raw string) string
- func Window[T any](items []T, size func(T) int, limit int64) ([]T, bool)
- type Analytics
- type Count
- type HeaderBlock
- type HeaderRule
- type ImportResult
- type NotifyConfig
- type NotifyStore
- func (s *NotifyStore) AllowDeployOutcome(ctx context.Context, resourceID string, succeeded bool) bool
- func (s *NotifyStore) Delete(ctx context.Context, resourceID string) error
- func (s *NotifyStore) Get(ctx context.Context, resourceID string) (NotifyConfig, bool, error)
- func (s *NotifyStore) Put(ctx context.Context, resourceID string, c NotifyConfig) error
- type Preset
- type SQLExecer
- type StatusCount
Constants ¶
const ( EventSuccess = "success" EventFailure = "failure" )
Event names accepted by the notify event filter.
const SourcePrefix = "preset:"
SourcePrefix labels preset header blocks so they can be replaced and ranked.
const TruncatedNotice = "[earlier build output truncated to fit the log size limit]"
TruncatedNotice is the marker line shown when older output was dropped to fit the cap.
Variables ¶
var Ranges = map[string]time.Duration{"24h": 24 * time.Hour, "7d": 7 * 24 * time.Hour, "30d": 30 * 24 * time.Hour}
Ranges are the windows the endpoint serves.
Functions ¶
func Apply ¶
func Apply(rs *spec.StaticRuleset, id string, l spec.StaticLimits) error
Apply replaces any earlier preset blocks in rs with the preset's, ranked after every other block. A header name the user sets anywhere is left to the user. An empty id only removes the preset.
func CacheDir ¶
CacheDir returns the per-site cache directory under root. The site name is validated so one site can never address another site's cache.
func CacheKey ¶
CacheKey derives a cache key from lockfile contents, so a changed lockfile starts a fresh cache.
func EvictOldest ¶
EvictOldest removes the oldest key directories of one site until its cache fits limit bytes. The key just used is spared so a build never deletes the cache it is about to read.
func LogExpired ¶
LogExpired reports whether a finished deploy's log is past its retention. A zero retention keeps logs forever.
func ParseEvents ¶
ParseEvents turns event names into filter flags; at least one is required.
Types ¶
type Analytics ¶
type Analytics struct {
Site string `json:"site"`
Range string `json:"range"`
Since time.Time `json:"since"`
GeneratedAt time.Time `json:"generated_at"`
RetentionDays int `json:"retention_days"`
Requests int `json:"requests"`
TopPages []Count `json:"top_pages"`
TopReferrers []Count `json:"top_referrers"`
Status []StatusCount `json:"status"`
Partial bool `json:"partial"`
}
Analytics is the body of GET /api/v1/static-sites/{name}/analytics. It holds no client address, cookie, country or query string.
type Count ¶
Count is a label with how many requests it covers.
func MergeReferrers ¶
MergeReferrers folds referrer labels to hosts, merges duplicates and keeps the top n.
type HeaderBlock ¶
HeaderBlock is one path pattern with its response headers.
type HeaderRule ¶
HeaderRule is one path pattern with the headers the preset sets on it.
type ImportResult ¶
type ImportResult struct {
Redirects []string
Headers []HeaderBlock
Unsupported []string
Sources []string
}
ImportResult is the converted config plus a report of what was skipped.
func ImportDir ¶
func ImportDir(dir string) (*ImportResult, error)
ImportDir inspects the root of dir, detects config files by shape and converts them. Nothing is written.
func (*ImportResult) Render ¶
func (r *ImportResult) Render() (redirects, headers string)
Render returns the _redirects and _headers file bodies.
type NotifyConfig ¶
type NotifyConfig struct {
Enabled bool `json:"enabled"`
OnSuccess bool `json:"on_success"`
OnFailure bool `json:"on_failure"`
}
NotifyConfig is one site's deploy notification switch and event filter.
func DefaultNotifyConfig ¶
func DefaultNotifyConfig() NotifyConfig
DefaultNotifyConfig is what a site without a stored row behaves like.
func (NotifyConfig) Allows ¶
func (c NotifyConfig) Allows(succeeded bool) bool
Allows reports whether a deploy outcome should be sent.
func (NotifyConfig) Events ¶
func (c NotifyConfig) Events() []string
Events lists the enabled event names in a stable order.
type NotifyStore ¶
type NotifyStore struct {
// contains filtered or unexported fields
}
NotifyStore persists NotifyConfig per resource ID.
func NewNotifyStore ¶
func NewNotifyStore(db SQLExecer) *NotifyStore
NewNotifyStore wraps db, which must hold the pages_notify_settings table.
func (*NotifyStore) AllowDeployOutcome ¶
func (s *NotifyStore) AllowDeployOutcome(ctx context.Context, resourceID string, succeeded bool) bool
AllowDeployOutcome lets the deploy dispatcher skip filtered events; a read error fails open.
func (*NotifyStore) Delete ¶
func (s *NotifyStore) Delete(ctx context.Context, resourceID string) error
Delete drops the row so the site returns to the default.
func (*NotifyStore) Get ¶
func (s *NotifyStore) Get(ctx context.Context, resourceID string) (NotifyConfig, bool, error)
Get returns the stored config and whether a row exists.
func (*NotifyStore) Put ¶
func (s *NotifyStore) Put(ctx context.Context, resourceID string, c NotifyConfig) error
Put creates or replaces the config.
type Preset ¶
type Preset struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Compression []string `json:"compression"`
Headers []HeaderRule `json:"headers"`
Security map[string]string `json:"security"`
}
Preset is one named bundle of cache, compression and security header choices.
type SQLExecer ¶
type SQLExecer interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
SQLExecer is the slice of *sql.DB the store needs; the alerting DB satisfies it.
type StatusCount ¶
StatusCount is one exact response code with its request count.
func StatusBreakdown ¶
func StatusBreakdown(codes []int) []StatusCount
StatusBreakdown counts exact response codes, most frequent first.