eval

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package eval handles the Evaluation of a req script.

Index

Constants

This section is empty.

Variables

View Source
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,
	}
)
View Source
var (
	WriteCmd = &Command{
		Name: "write",
		Argc: -1,
		Func: write(os.Stdout),
	}

	WritelnCmd = &Command{
		Name: "writeln",
		Argc: -1,
		Func: writeln(os.Stdout),
	}
)
View Source
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.

View Source
var CookieCmd = &Command{
	Name: "cookie",
	Argc: 1,
	Func: cookie,
}
View Source
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.

View Source
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.

View Source
var EnvCmd = &Command{
	Name: "env",
	Argc: 1,
	Func: env,
}

EnvCommand implements the env command for retrieving environment variables.

View Source
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.

View Source
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.

View Source
var SendCmd = &Command{
	Name: "send",
	Argc: 1,
	Func: send,
}

SendCmd implements the send command for sending a request.

View Source
var SniffCmd = &Command{
	Name: "sniff",
	Argc: 1,
	Func: sniff,
}

SniffCmd implements the sniff command for inspecting the content type of a stream.

View Source
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

type CommandError struct {
	Op  string
	Cmd string
	Err error
}

CommandError records an error and the operation and command that caused it.

func (*CommandError) Error

func (e *CommandError) Error() string

type CommandFunc

type CommandFunc func(cmd string, args []value.Value) (value.Value, error)

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.

func (*Context) Copy

func (c *Context) Copy() *Context

Copy returns a copy of the current Context.

func (*Context) Get

func (c *Context) Get(name string) (value.Value, error)

Get returns an valect of the given name. If no valect exists, then this errors.

func (*Context) Put

func (c *Context) Put(name string, val value.Value)

Put puts the given valect into the current Context under the given name.

type Error

type Error struct {
	Pos syntax.Pos
	Err error
}

Error records an error that occurred during Evaluation and the position at which the error occurred and the original error itself.

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

func New

func New(out io.Writer) *Evaluator

New returns a new evaluator for evaluating req scripts. The given writer is used as the standard output for the write and writeln commands.

func (*Evaluator) AddCmd

func (e *Evaluator) AddCmd(cmd *Command)

AddCmd adds the given command to the Evaluator.

func (*Evaluator) Eval

func (e *Evaluator) Eval(c *Context, n syntax.Node) (value.Value, error)

Eval Evaluates the given node and returns the value it Evaluates to if any.

func (*Evaluator) Run

func (e *Evaluator) Run(nn []syntax.Node) error

Run Evaluates all of the given nodes.

Jump to

Keyboard shortcuts

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