Documentation
¶
Overview ¶
Package syntaxedit reads the entries of a request file as a model a form can show, and edits the file one element at a time: every edit replaces only the bytes of its target, keeping comments, blank lines and formatting elsewhere, and is checked by parsing the result. Every offset of the API is in UTF-16 code units, as the language server's.
Index ¶
- Variables
- func EntryAt(models []EntryModel, offset int) int
- type EntryModel
- type LoginSpec
- type Range
- type Result
- func AddAssert(name string, src []byte, n int, assert string) (*Result, error)
- func AddCapture(name string, src []byte, n int, capture, query string) (*Result, error)
- func AddEntry(name string, src []byte, specs ...syntax.EntrySpec) (*Result, error)
- func AddLoginEntry(name string, src []byte, before int, spec LoginSpec) (*Result, error)
- func AddRow(name string, src []byte, n int, section Section, key, value string) (*Result, error)
- func ApplyEdits(name string, src []byte, rows []RowInsert) (*Result, error)
- func EnsureSection(name string, src []byte, n int, section Section) (*Result, error)
- func RemoveEntry(name string, src []byte, n int) (*Result, error)
- func RemoveRow(name string, src []byte, n int, section Section, i int) (*Result, error)
- func RemoveSection(name string, src []byte, n int, section Section) (*Result, error)
- func SetBody(name string, src []byte, n int, body string) (*Result, error)
- func SetMethod(name string, src []byte, n int, method string) (*Result, error)
- func SetRow(name string, src []byte, n int, section Section, i int, key, value string) (*Result, error)
- func SetStatus(name string, src []byte, n int, status string) (*Result, error)
- func SetURL(name string, src []byte, n int, url string) (*Result, error)
- func ToggleRow(name string, src []byte, n int, section Section, i int) (*Result, error)
- type Row
- type RowInsert
- type Section
- type TextEdit
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("syntaxedit: invalid edit")
ErrInvalid reports an edit refused because its result does not read as asked (a value that would start a comment, break a line, ...).
Functions ¶
func EntryAt ¶
func EntryAt(models []EntryModel, offset int) int
EntryAt returns the 1-based index of the entry at offset (UTF-16) of the source the models were built from: the entry whose range holds it, or the last entry starting before it; 0 before the first entry.
Types ¶
type EntryModel ¶
type EntryModel struct {
// Index is the entry's 1-based position.
Index int
// Range spans the entry, from its method to the end of its last
// line (comment lines above the method excluded).
Range Range
Method string
MethodRange Range
URL string
URLRange Range
// HasResponse tells whether the entry has an expected response.
HasResponse bool
Status string
StatusRange Range
// HasBody tells whether the request has a body; Body is its source
// text.
HasBody bool
Body string
BodyRange Range
// Rows are the rows of every section present, by section.
Rows map[Section][]Row
}
EntryModel is an entry as a form shows it. Text values are source text, as written.
type LoginSpec ¶
type LoginSpec struct {
// Request is the login request; its Response status defaults to 200.
Request syntax.EntrySpec
// Capture is the variable the token is captured in, from the response
// at JSONPath (e.g. "$.access_token").
Capture string
JSONPath string
// Redact makes the capture a secret.
Redact bool
}
LoginSpec is an entry that logs in and captures a token from its JSON response, for the entries after it (a form's "add login" action, an OAuth2 import suggestion).
type Range ¶
type Range struct{ Start, End int }
Range is a half-open range of UTF-16 code units [Start, End).
type Result ¶
Result is an edited source and the edit that produced it from the original.
func AddCapture ¶
AddCapture appends a capture `name: query...` (source text) to entry n.
func AddLoginEntry ¶
AddLoginEntry inserts the login entry spec before entry before (1-based; past the last entry: at the end).
func AddRow ¶
AddRow appends a row to section name of entry n, adding the section (and an `HTTP *` response for a response section) when missing.
func ApplyEdits ¶
ApplyEdits adds rows to a file, each rendered and checked like AddRow (one more row in its section, the same entries), in order. It is the only way an edit made elsewhere (an import suggestion) reaches a file. The result has one edit from src.
func EnsureSection ¶
EnsureSection adds an empty section name to entry n when missing (and an `HTTP *` response for a response section).
func RemoveEntry ¶
RemoveEntry removes entry n with the comment lines directly above it, up to the next entry's own comment lines (the last entry: from the end of the previous one).
func RemoveRow ¶
RemoveRow removes row i of section name of entry n, with its line. A section left empty keeps its header.
func RemoveSection ¶
RemoveSection removes section name of entry n, its header and rows (disabled ones too); a missing section is left as is.
func SetBody ¶
SetBody sets the request body of entry n to body, source text (JSON, a multiline string, ...); an empty body removes it.
func SetRow ¶
func SetRow(name string, src []byte, n int, section Section, i int, key, value string) (*Result, error)
SetRow replaces the key and value (source text) of row i (0-based, disabled rows counted) of section name of entry n. A disabled row stays disabled.
func SetStatus ¶
SetStatus sets the expected status of entry n ("*" or digits), adding an `HTTP <status>` response when the entry has none.
type Row ¶
type Row struct {
Key, Value string
Disabled bool
// Range is the row's text, from its key to the end of its value.
Range Range
}
Row is one row of a section. Key and Value are source text, as written (an assert has only a Value, its whole text). A disabled row is a `# key: value` comment line that reads as a row of its section.
type RowInsert ¶
RowInsert is a row an edit made elsewhere (an import suggestion) adds to a file: Key and Value are source text, rendered like AddRow's.
type Section ¶
type Section string
Section names a list of rows of an entry.
const ( Headers Section = "headers" Query Section = "query" Form Section = "form" Multipart Section = "multipart" Cookies Section = "cookies" BasicAuth Section = "basic-auth" Options Section = "options" ResponseHeaders Section = "response-headers" Captures Section = "captures" Asserts Section = "asserts" // Grpc is [SondeGrpc] (.sonde only): proto, import-path, protoset. Grpc Section = "grpc" )
Sections. Request headers and response headers are rows without a section header.