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
- type Change
- type Entry
- type RangeError
- type Recorded
- type Store
- func (s *Store) Clear(env, name string) (int, error)
- func (s *Store) Get(env, name string, index int) (Entry, error)
- func (s *Store) Keep() int
- func (s *Store) List(env, name string) ([]Entry, error)
- func (s *Store) Record(env, name string, at time.Time, result []byte) error
- func (s *Store) Requests(env string) ([]Recorded, error)
Constants ¶
const ( Added = "added" Removed = "removed" Changed = "changed" )
Change operations.
const DefaultEnv = session.DefaultEnv
DefaultEnv names the environment of a run that used none, as the session does.
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 ¶
RangeError is a Get for an entry that does not exist.
func (*RangeError) Error ¶
func (e *RangeError) Error() string
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the history of one project.
func New ¶
New returns the store for a project root keeping keep entries per request and environment. Nothing is written until Record.
func (*Store) Clear ¶
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) List ¶
List returns the entries for name in env, newest first, without their results. No history is an empty list, not an error.