Documentation ¶
Overview ¶
Package eval handles the Evaluation of a req script.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ReadCmd implements the read command for reading all of the data in a // given stream. ReadCmd = &Command{ Name: "read", Argc: 1, Func: read, } // ReadlnCmd implements the readln command for reading a single line from // the given stream. ReadlnCmd = &Command{ Name: "readln", Argc: 1, Func: readln, } )
var ( WriteCmd = &Command{ Name: "write", Argc: -1, Func: write(os.Stdout), } WritelnCmd = &Command{ Name: "writeln", Argc: -1, Func: writeln(os.Stdout), } )
var ( HeadCmd = &Command{ Name: "HEAD", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 2 { args = args[:2] } return request("HEAD", args) }, } OptionsCmd = &Command{ Name: "OPTIONS", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 2 { args = args[:2] } return request("OPTIONS", args) }, } GetCmd = &Command{ Name: "GET", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 2 { args = args[:2] } return request("GET", args) }, } PostCmd = &Command{ Name: "POST", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 3 { args = args[:3] } return request("POST", args) }, } PatchCmd = &Command{ Name: "PATCH", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 3 { args = args[:3] } return request("PATCH", args) }, } PutCmd = &Command{ Name: "PUT", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 3 { args = args[:3] } return request("PUT", args) }, } DeleteCmd = &Command{ Name: "DELETE", Argc: -1, Func: func(cmd string, args []value.Value) (value.Value, error) { if len(args) < 1 { return nil, &CommandError{ Op: "call", Cmd: cmd, Err: errNotEnoughArgs, } } if len(args) > 2 { args = args[:2] } return request("DELETE", args) }, } )
HeadCmd, OptionsCmd, GetCmd, PostCmd, PatchCmd, PutCmd, DeleteCmd, are the request family of commands for those respective methods. Each of these will take at most 3 arguments for building the request, the first being the endpoint, the second the header, and the third the request body.
var CookieCmd = &Command{
Name: "cookie",
Argc: 1,
Func: cookie,
}
var (
DecodeCmd = &Command{
Name: "decode",
Argc: 2,
Func: decode,
}
)
DecodeCmd implements the decode family of commands for decoding data back to their original form. Each decode command has a respective encode command for encoding data into a different form.
var (
EncodeCmd = &Command{
Name: "encode",
Argc: 2,
Func: encode,
}
)
EncodeCmd implements the encode family of commands for encoding data into various forms. Each encode command has a respective decode command for decoding data back into its original form.
var EnvCmd = &Command{
Name: "env",
Argc: 1,
Func: env,
}
EnvCommand implements the env command for retrieving environment variables.
var ExitCmd = &Command{
Name: "exit",
Argc: 1,
Func: exit,
}
ExitCmd implements the exit command that will cause the current script to exit with the given status code.
var OpenCmd = &Command{
Name: "open",
Argc: 1,
Func: open,
}
OpenCmd implements the open command for file reading. This will open the file for reading and writing. If the given file does not exist then one is created. All directories in the path to the file will be created if they do not already exist.
var SendCmd = &Command{
Name: "send",
Argc: 1,
Func: send,
}
SendCmd implements the send command for sending a request.
var SniffCmd = &Command{
Name: "sniff",
Argc: 1,
Func: sniff,
}
SniffCmd implements the sniff command for inspecting the content type of a stream.
var TlsCmd = &Command{
Name: "tls",
Argc: -1,
Func: tlsfn,
}
TlsCmd implements the tls command for sending a request over TLS using the given certificates.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { Name string // The name of the command. Argc int // The number of arguments for the command, -1 for unlimited. Func CommandFunc // The function to execute for the command. }
type CommandError ¶
CommandError records an error and the operation and command that caused it.
func (*CommandError) Error ¶
func (e *CommandError) Error() string
type CommandFunc ¶
CommandFunc is the function for handling the invocation of a command. This is passed the name of the command being invoked, and the list of arguments given.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context stores the variables that have been set during a script's Evaluation.
type Error ¶
Error records an error that occurred during Evaluation and the position at which the error occurred and the original error itself.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
func New ¶
New returns a new evaluator for evaluating req scripts. The given writer is used as the standard output for the write and writeln commands.