types

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package types holds the values Hanzo services share.

It imports the standard library only, so a service can depend on a value without inheriting the machinery of whoever else uses it.

A value earns a place here when two or more services must agree on it exactly. Fetching, storing and recording are effects, and an effect belongs with the service that owns it, next to the schema or transport it acts on.

Index

Constants

View Source
const Horizon = 2 * 365 * 24 * time.Hour

Horizon is how far back a window may reach: the retention the warehouses behind these series keep. "all" resolves to exactly this, so a caller asking for everything is told the real span it got rather than an open bound the store cannot honour.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

type Interval string

Interval is the width of one bucket in a metered time series.

The set is closed at Hour and Day. A bucket function is not a bindable parameter in the engines that serve these series, so the interval reaches a query by interpolation; keeping the set closed means a request cannot put anything else there.

const (
	Hour Interval = "hour"
	Day  Interval = "day"
)

func (Interval) Step

func (i Interval) Step() time.Duration

Step is how much time one bucket covers.

type Window

type Window struct {
	Label    string
	Start    time.Time
	End      time.Time
	Interval Interval
}

Window is a half-open time range [Start, End) and the interval its series buckets to.

Label is the range as the caller asked for it, defaulted when the caller asked for nothing, so a response can say which window it answers without the caller re-deriving it.

func ParseWindow

func ParseWindow(label, start, end string, now time.Time) (Window, error)

ParseWindow resolves a range request into an absolute window.

A relative label is a count and a unit — "24h", "90d", any <N>h or <N>d up to Horizon — so a window nobody enumerated still resolves. "day", "week" and "month" name the common ones, "all" reaches back to Horizon, and "custom" reads start and end, each RFC3339 or unix seconds, end defaulting to now and having to follow start.

A label that is neither is an error rather than a silent default, so a typo cannot quietly change the window a caller is shown, and a span past Horizon is refused by its own name rather than served short: on a series that carries money, a window that answers less than it was asked for is worse than one that refuses.

now is a parameter so the window is a function of the arguments alone.

Jump to

Keyboard shortcuts

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