history

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package history keeps the last few responses of each named request, per environment, so "what did this return yesterday?" has an answer. It is off unless apic.yaml sets `history: N`. Entries live under .apic/history/<env>/<request>/, one JSON file each, beside the session and under the same rules: the directory ignores itself and the files are 0600, since a response may hold data nobody wants in a commit.

Index

Constants

View Source
const (
	Added   = "added"
	Removed = "removed"
	Changed = "changed"
)

Change operations.

View Source
const DefaultEnv = session.DefaultEnv

DefaultEnv names the environment of a run that used none, as the session does.

View Source
const Dir = "history"

Dir is the history directory under the project's .apic directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	// Path is "status"; a JSONPath into a JSON body, such as
	// $.user.roles[2]; "line N" for a text body; or "body" when the bodies
	// cannot be compared piece by piece (binary, or too long to diff).
	Path string `json:"path"`
	Op   string `json:"op"` // "added", "removed" or "changed"
	// From and To are the values as JSON: a JSON body's values as they
	// are, a text line as a string. One of them is absent for an addition
	// or a removal, and both for a "body" change.
	From json.RawMessage `json:"from,omitempty"`
	To   json.RawMessage `json:"to,omitempty"`
}

Change is one difference between two recorded responses.

func Compare

func Compare(from, to json.RawMessage) ([]Change, error)

Compare lists what changed from one recorded result to another: the status, then the body. JSON bodies are compared by structure, object keys in sorted order and arrays index by index; text bodies line by line. Headers are left out, since a Date or a request id differs every time.

type Entry

type Entry struct {
	Index      int       `json:"index"`
	Time       time.Time `json:"time"`
	OK         bool      `json:"ok"`
	Status     int       `json:"status"`
	StatusText string    `json:"status_text,omitempty"`
	DurationMs int64     `json:"duration_ms"`
	Size       int       `json:"size"`
	// File is the entry's path relative to the project root.
	File string `json:"file"`
	// Result is the run's result as `apic run --json` prints it, with
	// sensitive headers masked and, for a --redact run, every value.
	Result json.RawMessage `json:"-"`
}

Entry is one recorded response. Index counts from 1, the newest.

type RangeError

type RangeError struct {
	Name  string
	Index int
	Have  int
}

RangeError is a Get for an entry that does not exist.

func (*RangeError) Error

func (e *RangeError) Error() string

type Recorded

type Recorded struct {
	Request string `json:"request"`
	Entries int    `json:"entries"`
}

Recorded is a request that has history in an environment.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the history of one project.

func New

func New(root string, keep int) *Store

New returns the store for a project root keeping keep entries per request and environment. Nothing is written until Record.

func (*Store) Clear

func (s *Store) Clear(env, name string) (int, error)

Clear removes the history of name in env; an empty name clears the whole environment, and env "*" every environment. It reports how many entries it removed.

func (*Store) Get

func (s *Store) Get(env, name string, index int) (Entry, error)

Get returns entry index (1 is the newest) for name in env, with its result.

func (*Store) Keep

func (s *Store) Keep() int

Keep is the number of entries kept per request and environment.

func (*Store) List

func (s *Store) List(env, name string) ([]Entry, error)

List returns the entries for name in env, newest first, without their results. No history is an empty list, not an error.

func (*Store) Record

func (s *Store) Record(env, name string, at time.Time, result []byte) error

Record stores result, the JSON of a run's result, as the newest entry for name in env, then drops the oldest entries beyond Keep.

func (*Store) Requests

func (s *Store) Requests(env string) ([]Recorded, error)

Requests lists the requests with history in env, by name.

Jump to

Keyboard shortcuts

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