Help us shape the future of Go! Take the 2026 Go Developer Survey

histwin

package
v0.40.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package histwin carries the free plan's history window in a request context.

A free account (Rivolt Pro, Sprint 14) sees the last FreeDays days of drives and charges, and the current and previous two calendar months of statements. The window lives only in the context of a request that a windowed route's middleware has stamped: background jobs (the recorder, recaps, the statement email), repairs, the export and every other context carry none, so they see everything. The stores (drives, charges) narrow their reads when a window is present; nothing here deletes or hides a row from storage.

It has no dependencies so the stores can import it.

Index

Constants

View Source
const FreeDays = 90

FreeDays is the length of the free window, in days.

Variables

View Source
var ErrOutside = errors.New("histwin: outside the free history window")

ErrOutside is returned by a single-row read (a drive or charge by id) of a row older than the window. The row exists; the free plan does not show it.

Functions

func Allows

func Allows(ctx context.Context, t time.Time) bool

Allows reports whether a row that started at t is inside the window in ctx (always, when there is none).

func Clamp

func Clamp(ctx context.Context, from time.Time) time.Time

Clamp raises a client-supplied lower bound to the window: the result is never earlier than the window's start. A zero from means "no lower bound" and becomes the window's start.

func Since

func Since(ctx context.Context) (time.Time, bool)

Since is the window's oldest start time in ctx, if a window applies.

func With

func With(ctx context.Context, w W) context.Context

With returns ctx carrying w.

Types

type W

type W struct {
	// Since is the oldest start time a drive, charge or other timed row may have to be shown.
	Since time.Time
	// MoneyFrom is the first instant of the oldest calendar month (UTC) the Money statements show: the current month and the two before.
	MoneyFrom time.Time
	// Days is FreeDays, for clients.
	Days int
}

W is a window. The zero value is no window.

func Free

func Free(now time.Time) W

Free is the free plan's window at now.

func From

func From(ctx context.Context) (W, bool)

From is the window in ctx, if any.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL