project

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: 16 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 project discovers .http files under a directory and indexes their requests by name.

Index

Constants

View Source
const ConfigFile = "apic.yaml"

ConfigFile is the optional per-project configuration file name.

Variables

View Source
var ErrOutsideRoot = errors.New("resolves outside project root")

ErrOutsideRoot is a path that resolves outside the project root.

Functions

func Confine

func Confine(root, dir, rel string) (string, error)

Confine resolves rel against dir (an absolute rel as it is), follows symlinks, and returns the real path if it lies under root, else ErrOutsideRoot. The runner reads and writes files through it, and validate checks them with it, so the two agree on what is inside.

func Discover

func Discover(dir string) ([]string, error)

Discover lists the request files under a directory the way Load reads them: every *.http and *.rest, sorted, skipping hidden directories, node_modules, vendor and testdata. `apic fmt` uses the same walk so the two commands agree on what a project holds.

func RealPrefix

func RealPrefix(abs string) string

RealPrefix resolves the symlinks of the longest existing ancestor of a path that does not exist yet (a `>> file` into a new directory) and keeps the rest as written, so a root under a symlink (macOS's /var is /private/var) still contains what it should.

func Within

func Within(root, path string) (string, bool)

Within reports whether path (existing or not) lies under root, lexically: both are cleaned and the relative path must not start with `..`. It returns that relative path. Callers that must see through symlinks resolve both sides first.

Types

type AuthConfig

type AuthConfig struct {
	Default   string `yaml:"default"`   // auth spec applied to requests without `# @auth`, e.g. "aws region=eu-west-2"
	AllowExec bool   `yaml:"allowExec"` // permit `# @auth exec ...`
}

AuthConfig is the `auth:` section of apic.yaml.

type Config

type Config struct {
	Env     string `yaml:"env"`     // default environment
	Dir     string `yaml:"dir"`     // directory holding .http files, relative to the project root
	Timeout string `yaml:"timeout"` // default request timeout, e.g. "30s"
	Retry   string `yaml:"retry"`   // default retry policy, "<attempts> [interval]", e.g. "10 2s"
	Cookies bool   `yaml:"cookies"` // keep a cookie jar per environment in .apic/cookies.json
	// History keeps the last N responses of each named request, per
	// environment, under .apic/history; zero (the default) keeps none.
	History int `yaml:"history"`
	// Proxy is an http, https or socks5 proxy URL every request goes
	// through; NoProxy lists the hosts that bypass it. `--proxy` beats
	// it and `--no-proxy` switches it off for one command.
	Proxy   string   `yaml:"proxy"`
	NoProxy []string `yaml:"noProxy"`
	// MaxBodyBytes caps how much of a response apic will read into memory.
	// Zero means the built-in default; see runner.DefaultMaxBodyBytes.
	MaxBodyBytes int64      `yaml:"maxBodyBytes"`
	Auth         AuthConfig `yaml:"auth"`
	Test         TestConfig `yaml:"test"`
	TLS          TLSConfig  `yaml:"tls"`
}

Config is the content of apic.yaml.

type NotFoundError added in v0.1.4

type NotFoundError struct {
	Msg     string
	Closest []string
}

NotFoundError says a target names no request or file. Closest holds the known names nearest to the one given, best first, when any is near; runner.Usagef keeps them on the coded error, so --json and MCP carry them as `suggestions`.

func (*NotFoundError) Error added in v0.1.4

func (e *NotFoundError) Error() string

func (*NotFoundError) Suggestions added in v0.1.4

func (e *NotFoundError) Suggestions() []string

Suggestions returns the names the user probably meant (runner.Suggester).

type Project

type Project struct {
	Root        string // absolute path of the project root (where apic.yaml / env files live)
	Config      Config
	Files       []*httpfile.File
	Diagnostics []httpfile.Diagnostic
	// contains filtered or unexported fields
}

Project is a loaded set of .http files.

func Load

func Load(root string) (*Project, error)

Load discovers and parses every *.http and *.rest file under root.

func LoadOverlay

func LoadOverlay(root string, overlay map[string]string) (*Project, error)

LoadOverlay is Load with some files' content supplied rather than read: overlay maps an absolute path to the text to parse in its place, as an editor holds a buffer that is not saved yet. A request file in the overlay that is not on disk yet is loaded too.

func (*Project) CapturedBy

func (p *Project) CapturedBy(name string) *httpfile.Request

CapturedBy returns the first request that captures a variable of this name.

func (*Project) File

func (p *Project) File(path string) *httpfile.File

File returns the request file at path (relative to the root, or absolute), or nil. The whole path is the file name: a `#` in it is not a fragment.

func (*Project) Lookup

func (p *Project) Lookup(name string) (*httpfile.Request, error)

Lookup finds a request by name. It fails when the name is ambiguous.

func (*Project) Requests

func (p *Project) Requests() []*httpfile.Request

Requests returns every request in file order.

func (*Project) Resolve

func (p *Project) Resolve(target string) ([]*httpfile.Request, error)

Resolve turns a command-line target into one or more requests:

get-user            a request by @name
users.http          every request in that file, in order
users.http#get-user a named request in a specific file
users.http#3        the third request in that file

func (*Project) Validate

func (p *Project) Validate() []httpfile.Diagnostic

Validate returns parse diagnostics plus project-level checks.

type TLSConfig

type TLSConfig struct {
	CAFile     string             `yaml:"caFile"`     // PEM bundle added to the system roots
	CertFile   string             `yaml:"certFile"`   // client certificate (PEM)
	KeyFile    string             `yaml:"keyFile"`    // its private key (PEM); defaults to certFile
	VerifyHost *bool              `yaml:"verifyHost"` // verify the server certificate; default true
	Hosts      map[string]TLSHost `yaml:"hosts"`      // per-host overrides, by host name or *.suffix
}

TLSConfig is the `tls:` section of apic.yaml. Paths are relative to the project root and confined to it.

type TLSHost

type TLSHost struct {
	CAFile     string `yaml:"caFile"`
	CertFile   string `yaml:"certFile"`
	KeyFile    string `yaml:"keyFile"`
	VerifyHost *bool  `yaml:"verifyHost"`
}

TLSHost overrides TLSConfig for one host.

type TestConfig

type TestConfig struct {
	Paths []string `yaml:"paths"` // feature files or directories, relative to the root (default: features)
}

TestConfig is the `test:` section of apic.yaml.

Jump to

Keyboard shortcuts

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