Documentation
¶
Overview ¶
Package project discovers .http files under a directory and indexes their requests by name.
Index ¶
- Constants
- Variables
- func Confine(root, dir, rel string) (string, error)
- func Discover(dir string) ([]string, error)
- func RealPrefix(abs string) string
- func Within(root, path string) (string, bool)
- type AuthConfig
- type Config
- type Project
- func (p *Project) CapturedBy(name string) *httpfile.Request
- func (p *Project) File(path string) *httpfile.File
- func (p *Project) Lookup(name string) (*httpfile.Request, error)
- func (p *Project) Requests() []*httpfile.Request
- func (p *Project) Resolve(target string) ([]*httpfile.Request, error)
- func (p *Project) Validate() []httpfile.Diagnostic
- type TLSConfig
- type TLSHost
- type TestConfig
Constants ¶
const ConfigFile = "apic.yaml"
ConfigFile is the optional per-project configuration file name.
Variables ¶
var ErrOutsideRoot = errors.New("resolves outside project root")
ErrOutsideRoot is a path that resolves outside the project root.
Functions ¶
func Confine ¶
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 ¶
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 ¶
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.
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 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 LoadOverlay ¶
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 ¶
CapturedBy returns the first request that captures a variable of this name.
func (*Project) 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) Resolve ¶
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.