Documentation
¶
Overview ¶
//////////////////////////////////////////////////////////////////// Manage global data, options, and common access functions
globalStore -- map of global variables and data structures
The globalStore is used to hold variables that the set command can manage and command parser can leverage for variable substitution It also hold references to interfaces that enable higher level constructs
Best practice for globalstore is to prefix the variable name with an indicator of the command or function of the variable. The "_" prefix works great to store default information that can be easily accessed through variable substitution. The enumeration of global store returns "_" prefixed variables last.
Another best practice is to use $ prefix to indicate a variable may be considered temporary. There are commands to delete all variables starting with $.
////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////// This package makes a good starting point
REM is actually executed internally in the processor as it does not work on parsed line (for now) ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
Substitution functions Registered substation functions can be used in variable substitution to calculate values, provide variable formatting or generate unique data values. Substitution functions have the ability to key any function call so the same value can be returned in a subsequent call. A different key or absence of key can result in a different value. For example, a substitution function can generate a unique ID to be used in a variable or HTTP body. Using a key allows the same guid to be substituted multiple times. Without a key, a function is assumed to return a different value but that is not guaranteed (for example a gettime() called repeatedly may return the same time due to speed of the CPU) A package init function can register functions using RegisterSubstitutionHandler. The function registered identifies a function name and function group. The function name is used in the substitution process to identify the function to call. The functions group membership identifies the cached data used to manage key'ed instance of function data. Multiple functions in the same group can use the same cache data to ensure consistency for a given key. A function is defined as: %%funcname([key, [fmt, [option]]])%% When a function is parsed, the funcname is used to identify a function to call. The function is given any previous data returned from a function within a group (a group shares one cache item). Groups allow multiple data elements to be associated together and accessed through a single key. For example: A function group may manage the generation and display of a random mailing address. When any function in the group is called, it would generate a random mailing address if one was not previously generated. When the function returns the value for substitution it also returns the raw data used to generate it so the substitution package can maintain that state with a key. When any other function in the group is called with the same key, it will get the raw data provided. There is a newguid() function included in the system to serve as an example.
Index ¶
- Constants
- Variables
- func AddAlias(key string, command string, force bool) error
- func AddCommand(name string, category string, cmd Command)
- func AddCommands()
- func AddCommonCmdOptions(set CmdSet, options ...int)
- func ClearCmdOptions()
- func CmdParse(set CmdSet, tokens []string) error
- func ColumnizeTokens(tokens []string, columns int, width int) []string
- func CommandProcessesLine(cmd interface{}) bool
- func CommandProcessor(defaultPrompt string, reader io.Reader, singleStep bool, allowAbort bool) (int, bool)
- func CommandRequestsNoStep(cmd interface{}) bool
- func CommandRequestsQuit(cmd interface{}) bool
- func ConsoleWriter() io.Writer
- func ContainsCommand(cmd string, tokens []string) bool
- func Delay(value time.Duration)
- func DisplayCmdHelp(set *getopt.Set, cmd string)
- func DisplayHelp()
- func EnableGlobalOptions()
- func EnumerateGlobals(fn func(key string, value interface{}), filter func(string, interface{}) bool)
- func ErrorWriter() io.Writer
- func FormBodyValidate(debug bool, body string)
- func FormatMsTime(v float64) string
- func GetAlias(key string) (string, error)
- func GetAllAliasKeys() []string
- func GetBinaryFileContents(filename string) ([]byte, error)
- func GetCmdConcurrencyValue() int
- func GetCmdHeaderValues(fallback string) string
- func GetCmdIterationThrottleMs() int
- func GetCmdIterationValue() int
- func GetCmdOutputFileName() string
- func GetCmdTimeoutValueMs() int64
- func GetCmdUrlValue(fallback string) (result string)
- func GetExeDirectory() string
- func GetFileContents(filename string) (string, error)
- func GetFileContentsOfType(file string, extension string) (string, error)
- func GetGlobal(key string) interface{}
- func GetGlobalString(key string) string
- func GetGlobalStringWithFallback(key string, fallback string) string
- func GetInitDirectory() string
- func GetLine(prompt string) string
- func GetPassword(prompt string) string
- func GetSubstitutionFunctions()
- func GetValidatedFileName(file string, extension string) (string, error)
- func GetValueAsDate(i interface{}) (time.Time, error)
- func GetValueFromAuthHistory(index int, path string) (string, error)
- func GetValueFromCookieHistory(index int, path string) (string, error)
- func GetValueFromHeaderHistory(index int, path string) (string, error)
- func GetValueFromHttpStatusHistory(index int) (string, error)
- func GetValueFromResultHistory(index int, path string) (string, error)
- func GetX509Pool() *x509.CertPool
- func InitializeCommonCmdOptions(set CmdSet, options ...int)
- func InitializeGlobal(key string, value interface{}) error
- func InitializeShell()
- func IsBody(l []DisplayOption) bool
- func IsCmdBasicAuthEnabled() bool
- func IsCmdCsvFormatEnabled() bool
- func IsCmdDebugEnabled() bool
- func IsCmdFormattedCsvEnabled() bool
- func IsCmdFullOutputEnabled() bool
- func IsCmdHeaderDisabled() bool
- func IsCmdHelpEnabled() bool
- func IsCmdLocalCertsEnabled() bool
- func IsCmdNetDebugEnabled() bool
- func IsCmdNoAuthEnabled() bool
- func IsCmdNoRedirectEnabled() bool
- func IsCmdOutputBodyEnabled() bool
- func IsCmdOutputCookieEnabled() bool
- func IsCmdOutputHeaderEnabled() bool
- func IsCmdOutputShortEnabled() bool
- func IsCmdPrettyPrintEnabled() bool
- func IsCmdQueryParamAuthEnabled() bool
- func IsCmdReconnectEnabled() bool
- func IsCmdSilentEnabled() bool
- func IsCmdSkipCertValidationEnabled() bool
- func IsCmdVerboseEnabled() bool
- func IsCmdWarmingEnabled() bool
- func IsCookies(l []DisplayOption) bool
- func IsDebugEnabled() bool
- func IsDisplayHelpEnabled() bool
- func IsFlowControl(err error, cmd FlowErrorCmd) bool
- func IsHeaders(l []DisplayOption) bool
- func IsNetDebugEnabled() bool
- func IsPrettyPrint(l []DisplayOption) bool
- func IsShort(l []DisplayOption) bool
- func IsSilentEnabled() bool
- func IsStatus(l []DisplayOption) bool
- func IsStringBinary(text string) bool
- func IsValidKey(key string) bool
- func IsVariableSubstitutionComplete(input string) bool
- func IsVerboseEnabled() bool
- func JsonBodyValidate(debug bool, body string)
- func JsonCompletionHandler(json string, resperr error, shortDisplay ShortDisplayFunc) error
- func LineParse(input string) []string
- func NewFlowError(msg string, cmd FlowErrorCmd) error
- func OnVerbose(format string, a ...interface{})
- func OpenFileForOutput(name string, truncate bool, append bool, newfile bool) (*os.File, error)
- func OutputResult(result Result, shortDisplay ShortDisplayFunc) (resperr error)
- func OutputWriter() io.Writer
- func ParseDuration(timeArg string, suffix ...string) (time.Duration, error)
- func PerformHealthCheck(client RestClient, url string) error
- func PerformVariableSubstitution(input string) string
- func ProcessJob(options JobOptions, jm JobMonitor)
- func PushError(resperror error) error
- func PushResponse(resp *RestResponse, resperror error) error
- func PushResult(result Result) error
- func PushText(contentType string, data string, resperror error) error
- func ReadLine()
- func RegisterSubstitutionHandler(function SubstitutionFunction)
- func RemoveAlias(key string) error
- func RemoveGlobal(key string)
- func ResetOutput() (io.Writer, error)
- func RestCompletionHandler(response *RestResponse, resperr error, shortDisplay ShortDisplayFunc) error
- func RunShell(options StartupOptions) (exitCode int)
- func SetAuthContext(ctx string, auth Auth)
- func SetDebug(val bool)
- func SetGlobal(key string, value interface{}) error
- func SetOutput(o io.Writer) error
- func SetSilent(val bool)
- func SetVerbose(val bool)
- func SortedMapKeys(mapData map[string]interface{}) []string
- func SortedStringSlice(commands []string) []string
- func SubstitutionFunctionHelp(o io.Writer, funcName string) error
- func SubstitutionFunctionHelpList(o io.Writer)
- func SubstitutionFunctionNames() []string
- func TryGetGlobalString(key string) (string, bool)
- func ValidateScriptExists(file string) (string, error)
- func XmlBodyValidate(debug bool, body string)
- type Abortable
- type Auth
- type BasicAuth
- type Benchmark
- func (bm *Benchmark) AddIterationMessage(i int, msg string)
- func (bm *Benchmark) Dump(label string, opts StandardOptions, showIterations bool)
- func (bm *Benchmark) DumpIterations(opts StandardOptions)
- func (bm *Benchmark) End()
- func (bm *Benchmark) EndIteration(i int)
- func (bm *Benchmark) HighTimeFmt() string
- func (bm *Benchmark) HighTimeInMs() float64
- func (bm *Benchmark) HlAverageFmt() string
- func (bm *Benchmark) HlAverageInMs() float64
- func (bm *Benchmark) LowTimeFmt() string
- func (bm *Benchmark) LowTimeInMs() float64
- func (bm *Benchmark) SetIterationStatus(i int, err error)
- func (bm *Benchmark) Start()
- func (bm *Benchmark) StartIteration(i int)
- func (bm *Benchmark) WallAverageFmt() string
- func (bm *Benchmark) WallAverageInMs() float64
- func (bm *Benchmark) WallTimeFmt() string
- func (bm *Benchmark) WallTimeInMs() float64
- type BenchmarkIteration
- type CmdSet
- type Command
- type CommandWithSubcommands
- type CookieAuth
- type DisplayOption
- type FlowControl
- type FlowError
- type FlowErrorCmd
- type HistoryMap
- type HistoryOptions
- func (ho *HistoryOptions) ClearPathOptions()
- func (ho HistoryOptions) GetNode(path string, result Result) (interface{}, error)
- func (ho HistoryOptions) GetValueFromHistory(index int, path string) (string, error)
- func (ho HistoryOptions) IsAuthPath() bool
- func (ho HistoryOptions) IsCookiePath() bool
- func (ho HistoryOptions) IsHeaderPath() bool
- func (ho HistoryOptions) IsHistoryPathOptionEnabled() bool
- func (ho HistoryOptions) IsHttpStatusPath() bool
- func (ho HistoryOptions) IsResultPathOption() bool
- func (ho *HistoryOptions) SetPathOption(payloadType ResultPayloadType)
- type JobCompletion
- type JobFunction
- type JobMaker
- type JobMonitor
- type JobOptions
- type JwtHeaderAuth
- type Line
- type LineProcessor
- type NoAuth
- type QueryParamAuth
- type QueryParmKeyValue
- type RemCommand
- func (cmd *RemCommand) AddOptions(set CmdSet)
- func (cmd *RemCommand) CommandCount() int
- func (cmd *RemCommand) DoNotClearError() bool
- func (cmd *RemCommand) DoNotCount() bool
- func (cmd *RemCommand) Execute(args []string) error
- func (cmd *RemCommand) ExecuteLine(line string, echoed bool) error
- func (cmd *RemCommand) RequestNoStep() bool
- func (cmd *RemCommand) RequestQuit() bool
- type RestClient
- func (r *RestClient) DisableCertValidation()
- func (r *RestClient) DisableRedirect()
- func (r *RestClient) DoGet(authContext Auth, url string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) DoMethod(method string, authContext Auth, url string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) DoMethodWithBody(method string, authContext Auth, url string, contentType string, data string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) DoWithForm(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) DoWithJson(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) DoWithJsonMarshal(method string, authContext Auth, url string, data interface{}) (*RestResponse, error)
- func (r *RestClient) DoWithXml(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
- func (r *RestClient) EnableRedirect()
- type RestResponse
- type Result
- type ResultContentType
- type ResultPayloadType
- type RunCommand
- type ShortDisplayFunc
- type StandardOptions
- func (o StandardOptions) Clear(options ...int) StandardOptions
- func (o *StandardOptions) GetBasicAuthContext(fallback Auth) Auth
- func (o *StandardOptions) GetCmdConcurrencyValue() int
- func (o *StandardOptions) GetCmdIterationThrottleMs() int
- func (o *StandardOptions) GetCmdIterationValue() int
- func (o *StandardOptions) GetCmdOutputFileName() string
- func (o *StandardOptions) GetHeaderValues(fallback string) string
- func (o *StandardOptions) GetQueryParamAuthContext(fallback Auth) Auth
- func (o *StandardOptions) GetTimeoutValueMs() int64
- func (o *StandardOptions) GetUrlValue(fallback string) (result string)
- func (o *StandardOptions) IsBasicAuthEnabled() bool
- func (o *StandardOptions) IsCsvOutputEnabled() bool
- func (o *StandardOptions) IsDebugEnabled() bool
- func (o *StandardOptions) IsFormattedCsvEnabled() bool
- func (o *StandardOptions) IsFullOutputEnabled() bool
- func (o *StandardOptions) IsHeaderDisabled() bool
- func (o *StandardOptions) IsHelpEnabled() bool
- func (o *StandardOptions) IsLocalCertsEnabled() bool
- func (o *StandardOptions) IsNetDebugEnabled() bool
- func (o *StandardOptions) IsNoAuthEnabled() bool
- func (o *StandardOptions) IsNoRedirectEnabled() bool
- func (o *StandardOptions) IsOutputBodyEnabled() bool
- func (o *StandardOptions) IsOutputCookieEnabled() bool
- func (o *StandardOptions) IsOutputHeaderEnabled() bool
- func (o *StandardOptions) IsOutputShortEnabled() bool
- func (o *StandardOptions) IsPrettyPrintEnabled() bool
- func (o *StandardOptions) IsQueryParamAuthEnabled() bool
- func (o *StandardOptions) IsReconnectEnabled() bool
- func (o *StandardOptions) IsSilentEnabled() bool
- func (o *StandardOptions) IsSkipCertValidationEnabled() bool
- func (o *StandardOptions) IsVerboseEnabled() bool
- func (o *StandardOptions) IsWarmingEnabled() bool
- func (o StandardOptions) Set(options ...int) StandardOptions
- type StartupOptions
- type StringList
- type SubstitutionFunction
- type SubstitutionHandler
- type SubstitutionItemHelp
- type Trackable
Constants ¶
const ( CmdHelp int = iota CmdDebug CmdNetDebug CmdVerbose CmdTimeout CmdSilent CmdUrl CmdNoAuth CmdBasicAuth CmdQueryParamAuth CmdBenchmarks CmdRestclient CmdNoRedirect // Encapsulated in CmdRestclient CmdSkipCertValidation // Encapsulated in CmdRestclient CmdFormatOutput )
Options to include with a command
const ( OptionDefaultTimeout = 30000 // In milliseconds OptionDefaultUrl = "" OptionDefaultIterations = 10 OptionDefaultConcurrency = 1 OptionDefaultIterationsThrottleMs = 0 OptionDefaultBasicAuth = "[user][,pwd]" OptionDefaultQueryParamAuth = "[[name,value]...]" OptionDefaultOutputFile = "" )
Default values for options
Variables ¶
var ( CategoryHttp = "Http" CategorySpecialized = "Specialized" CategoryUtilities = "Utility" CategoryBenchmarks = "Benchmark" CategoryTests = "Test" CategoryAnalysis = "Result Processing" CategoryHelp = "Help" )
Variables for supported categorizations of commands
var ( ErrArguments = errors.New("Invalid arguments") ErrInvalidValue = errors.New("Invalid value type") ErrNotFound = errors.New("Node not found") ErrInvalidPath = errors.New("Node path error") ErrInvalidKey = errors.New("Invalid key") ErrUnexpectedType = errors.New("Node is unexpected type") ErrDataType = errors.New("Invalid history data type") ErrNoHistory = errors.New("History not present") ErrArrayOutOfBounds = errors.New("Array index out of bounds") ErrInvalidSubCommand = errors.New("Invalid sub-command") ErrNotImplemented = errors.New("Command not implemented") )
Error variables
var ( DefaultInitFileName = ".rsconfig" DefaultInitFileExt = ".user" DefaultScriptFileExt = ".rshell" ProgramName = "RestShell" ProgramArgs = make([]string, 0, 0) )
Default settings for startup
var AnonymousAuth = NoAuth{}
var CalcTimeSince = time.Since
Functions isolated for mock testing
var DefaultScriptExtension = ".rshell"
var ExecutableDirectory string = ""
var InitDirectory string = ""
var LastError int = 0
Functions ¶
func AddCommand ¶
AddCommand -- Add a command to registry Cmd structures should avoid pointers to data structures so cmd structures can be duplicated into separate instances without data collision
func AddCommands ¶
func AddCommands()
func AddCommonCmdOptions ¶
AddCommonCmdOptions -- Add the given command options to the options supported by the current executing command
func ClearCmdOptions ¶
func ClearCmdOptions()
ClearCmdOptions -- Clear common command options by setting a new configuration.
func CmdParse ¶
CmdParse -- implements the parse/getopt function by hiding an Option type not to be exported in the interface
func CommandProcessesLine ¶
func CommandProcessesLine(cmd interface{}) bool
func CommandProcessor ¶
func CommandProcessor(defaultPrompt string, reader io.Reader, singleStep bool, allowAbort bool) (int, bool)
CommandProcessor -- Initiate the command interpretter using the given reader and options
func CommandRequestsNoStep ¶
func CommandRequestsNoStep(cmd interface{}) bool
func CommandRequestsQuit ¶
func CommandRequestsQuit(cmd interface{}) bool
func ConsoleWriter ¶
Output that is intended only for the console; typically help information and general shell/command processor debug
func ContainsCommand ¶
func DisplayCmdHelp ¶
func DisplayHelp ¶
func DisplayHelp()
func EnableGlobalOptions ¶
func EnableGlobalOptions()
func EnumerateGlobals ¶
func ErrorWriter ¶
General output that goes to the console stderr and a log file
func FormBodyValidate ¶
FormBodyValidate - Validate form data is ok; only display a warning if not
func FormatMsTime ¶
func GetAllAliasKeys ¶
func GetAllAliasKeys() []string
func GetBinaryFileContents ¶
func GetCmdConcurrencyValue ¶
func GetCmdConcurrencyValue() int
func GetCmdHeaderValues ¶
func GetCmdIterationThrottleMs ¶
func GetCmdIterationThrottleMs() int
func GetCmdIterationValue ¶
func GetCmdIterationValue() int
func GetCmdOutputFileName ¶
func GetCmdOutputFileName() string
func GetCmdTimeoutValueMs ¶
func GetCmdTimeoutValueMs() int64
func GetCmdUrlValue ¶
func GetExeDirectory ¶
func GetExeDirectory() string
func GetFileContents ¶
func GetFileContentsOfType ¶
GetFileContentsOfType -- read the file contents using a default extension if one was not provided
func GetGlobalString ¶
func GetInitDirectory ¶
func GetInitDirectory() string
func GetPassword ¶
func GetSubstitutionFunctions ¶
func GetSubstitutionFunctions()
func GetValidatedFileName ¶
Validate a file exists in full format or with expected extension added. Return the file that was verified that exists or an error. Note: extension must be all lower case
func GetValueAsDate ¶
GetValueAsDate -- given a scaler value in an interface convert it to a date if it is can be converted
func GetX509Pool ¶
GetX509Pool - Get the X509 pool to use; the system is used by default and a cert.pem file is appended if it can be found in the init directory, or the exe directory.
func InitializeCommonCmdOptions ¶
InitializeCommonCmdOptions initialize common command options
func InitializeGlobal ¶
Only set the global if not initialized already
func InitializeShell ¶
func InitializeShell()
func IsBody ¶
func IsBody(l []DisplayOption) bool
func IsCmdBasicAuthEnabled ¶
func IsCmdBasicAuthEnabled() bool
func IsCmdCsvFormatEnabled ¶
func IsCmdCsvFormatEnabled() bool
func IsCmdDebugEnabled ¶
func IsCmdDebugEnabled() bool
func IsCmdFormattedCsvEnabled ¶
func IsCmdFormattedCsvEnabled() bool
func IsCmdFullOutputEnabled ¶
func IsCmdFullOutputEnabled() bool
func IsCmdHeaderDisabled ¶
func IsCmdHeaderDisabled() bool
func IsCmdHelpEnabled ¶
func IsCmdHelpEnabled() bool
func IsCmdLocalCertsEnabled ¶
func IsCmdLocalCertsEnabled() bool
func IsCmdNetDebugEnabled ¶
func IsCmdNetDebugEnabled() bool
func IsCmdNoAuthEnabled ¶
func IsCmdNoAuthEnabled() bool
func IsCmdNoRedirectEnabled ¶
func IsCmdNoRedirectEnabled() bool
func IsCmdOutputBodyEnabled ¶
func IsCmdOutputBodyEnabled() bool
func IsCmdOutputCookieEnabled ¶
func IsCmdOutputCookieEnabled() bool
func IsCmdOutputHeaderEnabled ¶
func IsCmdOutputHeaderEnabled() bool
func IsCmdOutputShortEnabled ¶
func IsCmdOutputShortEnabled() bool
func IsCmdPrettyPrintEnabled ¶
func IsCmdPrettyPrintEnabled() bool
func IsCmdQueryParamAuthEnabled ¶
func IsCmdQueryParamAuthEnabled() bool
func IsCmdReconnectEnabled ¶
func IsCmdReconnectEnabled() bool
func IsCmdSilentEnabled ¶
func IsCmdSilentEnabled() bool
func IsCmdSkipCertValidationEnabled ¶
func IsCmdSkipCertValidationEnabled() bool
func IsCmdVerboseEnabled ¶
func IsCmdVerboseEnabled() bool
func IsCmdWarmingEnabled ¶
func IsCmdWarmingEnabled() bool
func IsCookies ¶
func IsCookies(l []DisplayOption) bool
func IsDebugEnabled ¶
func IsDebugEnabled() bool
func IsDisplayHelpEnabled ¶
func IsDisplayHelpEnabled() bool
func IsFlowControl ¶
func IsFlowControl(err error, cmd FlowErrorCmd) bool
func IsHeaders ¶
func IsHeaders(l []DisplayOption) bool
func IsNetDebugEnabled ¶
func IsNetDebugEnabled() bool
func IsPrettyPrint ¶
func IsPrettyPrint(l []DisplayOption) bool
func IsShort ¶
func IsShort(l []DisplayOption) bool
func IsSilentEnabled ¶
func IsSilentEnabled() bool
func IsStatus ¶
func IsStatus(l []DisplayOption) bool
func IsStringBinary ¶
func IsValidKey ¶
func IsVariableSubstitutionComplete ¶
IsVariableSubstitutionComplete -- Validate that variable substitution was complete (no variable syntax found)
func IsVerboseEnabled ¶
func IsVerboseEnabled() bool
func JsonBodyValidate ¶
JsonBodyValidate - Validate form data is ok; only display a warning if not
func JsonCompletionHandler ¶
func JsonCompletionHandler(json string, resperr error, shortDisplay ShortDisplayFunc) error
JsonCompletionHandler -- Helper function to push json result data and perform output processing
func LineParse ¶
LineParse -- Parse a command line into tokens handling escape sequences and double quotes
func NewFlowError ¶
func NewFlowError(msg string, cmd FlowErrorCmd) error
func OpenFileForOutput ¶
OpenFileForOutput -- open a file
func OutputResult ¶
func OutputResult(result Result, shortDisplay ShortDisplayFunc) (resperr error)
func OutputWriter ¶
General output that can go to the console stdout or to a log File Generally this is data, verbose output, and debug related to a function
func ParseDuration ¶
ParseDuration -- parses a duration value from text that may include time sufix [ms(default), S, see time.ParseDuration]
func PerformHealthCheck ¶
func PerformHealthCheck(client RestClient, url string) error
PerformHealthCheck - Valiate a default /health endpoint TODO: Evaluate moving this to specialized commands; it is not generic enough to be heres
func PerformVariableSubstitution ¶
PerformVariableSubstitution -- perform substitution on a string
func ProcessJob ¶
func ProcessJob(options JobOptions, jm JobMonitor)
ProcessJob -- Run the jobs based on provided options
func PushResponse ¶
func PushResponse(resp *RestResponse, resperror error) error
PushResponse -- Push a RestResponse into the history buffer
func PushResult ¶
PushResult -- push a Result structure into the history buffer
func RegisterSubstitutionHandler ¶
func RegisterSubstitutionHandler(function SubstitutionFunction)
RegisterSubstitutionHandler -- Register a substitution function
func RemoveAlias ¶
func RemoveGlobal ¶
func RemoveGlobal(key string)
func ResetOutput ¶
func RestCompletionHandler ¶
func RestCompletionHandler(response *RestResponse, resperr error, shortDisplay ShortDisplayFunc) error
RestCompletionHandler -- Helper function to push rest result and perform output processing
func RunShell ¶
func RunShell(options StartupOptions) (exitCode int)
RunShell -- process command line and init scripts and run command processor
func SetAuthContext ¶
func SetVerbose ¶
func SetVerbose(val bool)
func SortedMapKeys ¶
func SortedStringSlice ¶
func SubstitutionFunctionHelp ¶
SubstitutionFunctionHelp --
func SubstitutionFunctionHelpList ¶
SubstitutionFunctionHelpList -- Display help
func SubstitutionFunctionNames ¶
func SubstitutionFunctionNames() []string
SubstitutionFunctionNames --
func TryGetGlobalString ¶
func ValidateScriptExists ¶
ValidateScriptExists -- Validate the script exists by either basename or basename plus suffix return the file name modified with extension if necesssary. If the error is not a file existence problem the file is returned.
func XmlBodyValidate ¶
XmlBodyValidate - Validate form data is ok; only display a warning if not
Types ¶
type Abortable ¶
type Abortable interface {
Abort()
}
Abortable - interface for commands that support abort
type BasicAuth ¶
func NewBasicAuth ¶
type Benchmark ¶
type Benchmark struct {
Iterations []BenchmarkIteration
StartTime time.Time
Duration time.Duration
Note string
// contains filtered or unexported fields
}
func NewBenchmark ¶
func (*Benchmark) AddIterationMessage ¶
func (*Benchmark) Dump ¶
func (bm *Benchmark) Dump(label string, opts StandardOptions, showIterations bool)
func (*Benchmark) DumpIterations ¶
func (bm *Benchmark) DumpIterations(opts StandardOptions)
func (*Benchmark) EndIteration ¶
func (*Benchmark) HighTimeFmt ¶
func (*Benchmark) HighTimeInMs ¶
func (*Benchmark) HlAverageFmt ¶
func (*Benchmark) HlAverageInMs ¶
func (*Benchmark) LowTimeFmt ¶
func (*Benchmark) LowTimeInMs ¶
func (*Benchmark) SetIterationStatus ¶
func (*Benchmark) StartIteration ¶
func (*Benchmark) WallAverageFmt ¶
func (*Benchmark) WallAverageInMs ¶
func (*Benchmark) WallTimeFmt ¶
func (*Benchmark) WallTimeInMs ¶
type BenchmarkIteration ¶
type BenchmarkIteration struct {
Iteration int
WallTime int64 // Nano-seconds
Err error
Messages []string
Custom interface{}
// contains filtered or unexported fields
}
func (*BenchmarkIteration) DumpLine ¶
func (bi *BenchmarkIteration) DumpLine(opts StandardOptions, displayFmt string, start time.Time)
func (*BenchmarkIteration) WallTimeFmt ¶
func (bi *BenchmarkIteration) WallTimeFmt() string
func (*BenchmarkIteration) WallTimeInMs ¶
func (bi *BenchmarkIteration) WallTimeInMs() float64
type CmdSet ¶
type CmdSet interface {
Reset()
Usage()
SetProgram(string)
SetParameters(string)
SetUsage(func())
PrintUsage(io.Writer)
BoolLong(string, rune, ...string) *bool
StringLong(string, rune, string, ...string) *string
IntLong(string, rune, int, ...string) *int
Int64Long(string, rune, int64, ...string) *int64
StringListLong(string, rune, ...string) *StringList
Args() []string
Arg(int) string
NArgs() int
}
CmdSet -- Interface exposing the supported interfaces to commands for setting options
type CommandWithSubcommands ¶
type CommandWithSubcommands interface {
GetSubCommands() []string
}
CommandWithSubcommands - interface for commands that have sub-commands
type CookieAuth ¶
type DisplayOption ¶
type DisplayOption int
DisplayOption
const ( Body DisplayOption = iota Headers Cookies Status Short Pretty All )
DisplayOption values
func GetDefaultDisplayOptions ¶
func GetDefaultDisplayOptions() []DisplayOption
type FlowControl ¶
Flow Command interface to redirect flow after command execution
type FlowError ¶
type FlowError struct {
Message string
Cmd FlowErrorCmd
}
type FlowErrorCmd ¶
type FlowErrorCmd string
Flow commands affecting processor
var ( FlowQuit FlowErrorCmd = "q" FlowAbort FlowErrorCmd = "a" FlowGo FlowErrorCmd = "g" )
type HistoryMap ¶
func NewJsonHistoryMap ¶
func NewJsonHistoryMap(data string) (HistoryMap, error)
MakeJsonHistoryMap -- Create a HistoryMap for json content
func NewSimpleHistoryMap ¶
func NewSimpleHistoryMap(m map[string]string) (HistoryMap, error)
func NewTextHistoryMap ¶
func NewTextHistoryMap(text string) (HistoryMap, error)
func NewXmlHistoryMap ¶
func NewXmlHistoryMap(data string) (HistoryMap, error)
type HistoryOptions ¶
type HistoryOptions struct {
// contains filtered or unexported fields
}
HistoryOptions -- Common options for modifiers
func AddHistoryOptions ¶
func AddHistoryOptions(set CmdSet, payloadType ...ResultPayloadType) HistoryOptions
AddModifierOptions -- Add options for modifiers
func (*HistoryOptions) ClearPathOptions ¶
func (ho *HistoryOptions) ClearPathOptions()
func (HistoryOptions) GetNode ¶
func (ho HistoryOptions) GetNode(path string, result Result) (interface{}, error)
func (HistoryOptions) GetValueFromHistory ¶
func (ho HistoryOptions) GetValueFromHistory(index int, path string) (string, error)
Get the value from History and return as string
func (HistoryOptions) IsAuthPath ¶
func (ho HistoryOptions) IsAuthPath() bool
IsAuthPath -- Is the Authenticadtion token path option selected to parse JWT
func (HistoryOptions) IsCookiePath ¶
func (ho HistoryOptions) IsCookiePath() bool
IsCookiePath -- Is the cookie path option selected to extract cookie
func (HistoryOptions) IsHeaderPath ¶
func (ho HistoryOptions) IsHeaderPath() bool
IsHeaderPath -- Is the history path option selected
func (HistoryOptions) IsHistoryPathOptionEnabled ¶
func (ho HistoryOptions) IsHistoryPathOptionEnabled() bool
IsPathOptionEnabled -- True if any history path option is enabled
func (HistoryOptions) IsHttpStatusPath ¶
func (ho HistoryOptions) IsHttpStatusPath() bool
IsHeaderPath -- Is the history path option selected
func (HistoryOptions) IsResultPathOption ¶
func (ho HistoryOptions) IsResultPathOption() bool
IsPathOption -- Is the history path option selected
func (*HistoryOptions) SetPathOption ¶
func (ho *HistoryOptions) SetPathOption(payloadType ResultPayloadType)
type JobCompletion ¶
type JobCompletion func(job int, jm JobMonitor, resp *RestResponse)
JobCompletion -- Function prototype for a function that can parse the response
func MakeJobCompletionForExpectedStatus ¶
func MakeJobCompletionForExpectedStatus(status int) JobCompletion
MakeJobCompletionForExpectedStatus -- Create a completion handler to accept a different status than StatusOK
type JobFunction ¶
type JobFunction func() (*RestResponse, error)
JobFunction -- Function prototype for a function that will perform an instance of the job
type JobMaker ¶
type JobMaker func() JobFunction
JobMaker -- Function prototype for a function that can create an instance of the job function
type JobMonitor ¶
type JobMonitor interface {
Start()
End()
StartIteration(int)
EndIteration(int)
SetIterationStatus(int, error)
}
JobMonitor -- interface to support benchmark capabilities
type JobOptions ¶
type JobOptions struct {
Concurrency int
Iterations int
Duration time.Duration
ThrottleInMs int
EnableWarming bool
JobMaker JobMaker
CompletionHandler JobCompletion
CancelPtr *bool
}
JobOptions -- options available to the job processing engine
func GetJobOptionsFromParams ¶
func GetJobOptionsFromParams() JobOptions
GetJobOptionsFromParams -- initializes options from common command line options
type JwtHeaderAuth ¶
type JwtHeaderAuth struct {
AuthToken string
}
func NewJwtHeaderAuth ¶
func NewJwtHeaderAuth(t string) JwtHeaderAuth
func (JwtHeaderAuth) AddAuth ¶
func (a JwtHeaderAuth) AddAuth(req *http.Request)
func (JwtHeaderAuth) IsAuthed ¶
func (a JwtHeaderAuth) IsAuthed() bool
func (JwtHeaderAuth) ToString ¶
func (a JwtHeaderAuth) ToString() string
type Line ¶
type Line struct {
OriginalLine string
CmdLine string
Echo bool
Step bool
NoSubstitute bool
IsComment bool
Command string
ArgString string
}
Line -- a structure for a parsed line
func NewCommandLine ¶
NewCommandLine -- parse command line into a Line
func (*Line) GetCmdAndArguments ¶
GetCmdAndArguments -- get the tokens of the commmand line fully parsed
type LineProcessor ¶
LineProcessor - interface for commands that execute whole line
type QueryParamAuth ¶
type QueryParamAuth struct {
KeyPairs []QueryParmKeyValue
}
func NewQueryParamAuth ¶
func NewQueryParamAuth(kv ...string) QueryParamAuth
func (QueryParamAuth) AddAuth ¶
func (a QueryParamAuth) AddAuth(req *http.Request)
func (QueryParamAuth) GetKeyValue ¶
func (a QueryParamAuth) GetKeyValue(key string) (string, bool)
func (QueryParamAuth) IsAuthed ¶
func (a QueryParamAuth) IsAuthed() bool
func (QueryParamAuth) ToString ¶
func (a QueryParamAuth) ToString() string
type QueryParmKeyValue ¶
type RemCommand ¶
type RemCommand struct {
}
func NewRemCommand ¶
func NewRemCommand() *RemCommand
func (*RemCommand) AddOptions ¶
func (cmd *RemCommand) AddOptions(set CmdSet)
func (*RemCommand) CommandCount ¶
func (cmd *RemCommand) CommandCount() int
func (*RemCommand) DoNotClearError ¶
func (cmd *RemCommand) DoNotClearError() bool
func (*RemCommand) DoNotCount ¶
func (cmd *RemCommand) DoNotCount() bool
func (*RemCommand) Execute ¶
func (cmd *RemCommand) Execute(args []string) error
func (*RemCommand) ExecuteLine ¶
func (cmd *RemCommand) ExecuteLine(line string, echoed bool) error
func (*RemCommand) RequestNoStep ¶
func (cmd *RemCommand) RequestNoStep() bool
func (*RemCommand) RequestQuit ¶
func (cmd *RemCommand) RequestQuit() bool
type RestClient ¶
RestClient -- An object that makes REST calls
func NewRestClient ¶
func NewRestClient() RestClient
func NewRestClientFromOptions ¶
func NewRestClientFromOptions() RestClient
func (*RestClient) DisableCertValidation ¶
func (r *RestClient) DisableCertValidation()
DisableCertValidation -- A function to disable cert validation in the rest client TODO: cleanup relationship be between skipping verification and including certificates
func (*RestClient) DisableRedirect ¶
func (r *RestClient) DisableRedirect()
func (*RestClient) DoGet ¶
func (r *RestClient) DoGet(authContext Auth, url string) (resultResponse *RestResponse, resultError error)
func (*RestClient) DoMethod ¶
func (r *RestClient) DoMethod(method string, authContext Auth, url string) (resultResponse *RestResponse, resultError error)
func (*RestClient) DoMethodWithBody ¶
func (r *RestClient) DoMethodWithBody(method string, authContext Auth, url string, contentType string, data string) (resultResponse *RestResponse, resultError error)
DoMethodWithBody - Perform a HTTP request for the given method type and content provided
func (*RestClient) DoWithForm ¶
func (r *RestClient) DoWithForm(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
func (*RestClient) DoWithJson ¶
func (r *RestClient) DoWithJson(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
func (*RestClient) DoWithJsonMarshal ¶
func (r *RestClient) DoWithJsonMarshal(method string, authContext Auth, url string, data interface{}) (*RestResponse, error)
func (*RestClient) DoWithXml ¶
func (r *RestClient) DoWithXml(method string, authContext Auth, url string, data string) (resultResponse *RestResponse, resultError error)
DoWithXml -- Perform an HTTP method request with an XML body
func (*RestClient) EnableRedirect ¶
func (r *RestClient) EnableRedirect()
type RestResponse ¶
type RestResponse struct {
Text string
// contains filtered or unexported fields
}
RestResponse -- The response structure returned by a REST interface
func (*RestResponse) GetContentType ¶
func (resp *RestResponse) GetContentType() string
func (*RestResponse) GetCookies ¶
func (resp *RestResponse) GetCookies() []*http.Cookie
func (*RestResponse) GetHeader ¶
func (resp *RestResponse) GetHeader() http.Header
func (*RestResponse) GetStatus ¶
func (resp *RestResponse) GetStatus() int
GetStatus - Get the status return code in the response; if the response is invalid or not initialized it will return -1
func (*RestResponse) GetStatusString ¶
func (resp *RestResponse) GetStatusString() string
GetStatusString - Get the status code in string format for the response; if the response is invalid or not initialized it will return "Unknown Status".
type Result ¶
type Result struct {
Text string
Error error
HttpStatus int
HttpStatusString string
ContentType string
BodyMap HistoryMap
HeaderMap HistoryMap
CookieMap HistoryMap
AuthMap HistoryMap
// contains filtered or unexported fields
}
Result -- a result that can be placed in the history buffer and used by assertion handlers
func PeekResult ¶
PeekResult - Get a history result using an index. Index from the end of the array which was the last item appended
func (*Result) DumpCookies ¶
func (*Result) DumpHeader ¶
func (*Result) DumpResult ¶
func (r *Result) DumpResult(w io.Writer, options ...DisplayOption)
type ResultContentType ¶
type ResultContentType string
ResultContentType -- types of result data
var ( ResultContentUnknown ResultContentType = "unknown" ResultContentXml ResultContentType = "xml" ResultContentJson ResultContentType = "json" ResultContentText ResultContentType = "text" ResultContentHtml ResultContentType = "html" ResultContentCsv ResultContentType = "csv" ResultContentForm ResultContentType = "form" ResultContentBinary ResultContentType = "binary" )
Types of result data
type ResultPayloadType ¶
type ResultPayloadType int
const ( ResultPath ResultPayloadType = 1 AuthPath ResultPayloadType = 2 CookiePath ResultPayloadType = 3 HeaderPath ResultPayloadType = 4 AllPaths ResultPayloadType = 8 AlternatePaths ResultPayloadType = 9 // All paths but default as default is assumed )
Path options scenarios for different use cases
type RunCommand ¶
type RunCommand struct {
// contains filtered or unexported fields
}
func NewRunCommand ¶
func NewRunCommand() *RunCommand
func (*RunCommand) Abort ¶
func (cmd *RunCommand) Abort()
func (*RunCommand) AddOptions ¶
func (cmd *RunCommand) AddOptions(set CmdSet)
func (*RunCommand) CommandCount ¶
func (cmd *RunCommand) CommandCount() int
func (*RunCommand) DoNotClearError ¶
func (cmd *RunCommand) DoNotClearError() bool
func (*RunCommand) DoNotCount ¶
func (cmd *RunCommand) DoNotCount() bool
func (*RunCommand) Execute ¶
func (cmd *RunCommand) Execute(args []string) error
type ShortDisplayFunc ¶
ShortDisplayFunc -- A function can be used to pretty format the output or condense it
type StandardOptions ¶
type StandardOptions struct {
// contains filtered or unexported fields
}
Structure for all common option values
func GetStdOptions ¶
func GetStdOptions() StandardOptions
func (StandardOptions) Clear ¶
func (o StandardOptions) Clear(options ...int) StandardOptions
Clear -- Return a copy of the standard options with the specified options set to false for booleans or otherwise default values
func (*StandardOptions) GetBasicAuthContext ¶
func (o *StandardOptions) GetBasicAuthContext(fallback Auth) Auth
GetBasicAuthContext -- get the Auth context for the basic auth parameters specified
func (*StandardOptions) GetCmdConcurrencyValue ¶
func (o *StandardOptions) GetCmdConcurrencyValue() int
func (*StandardOptions) GetCmdIterationThrottleMs ¶
func (o *StandardOptions) GetCmdIterationThrottleMs() int
func (*StandardOptions) GetCmdIterationValue ¶
func (o *StandardOptions) GetCmdIterationValue() int
func (*StandardOptions) GetCmdOutputFileName ¶
func (o *StandardOptions) GetCmdOutputFileName() string
func (*StandardOptions) GetHeaderValues ¶
func (o *StandardOptions) GetHeaderValues(fallback string) string
func (*StandardOptions) GetQueryParamAuthContext ¶
func (o *StandardOptions) GetQueryParamAuthContext(fallback Auth) Auth
GetQueryParamAuthContext -- return the Auth context for query parameters specified in command
func (*StandardOptions) GetTimeoutValueMs ¶
func (o *StandardOptions) GetTimeoutValueMs() int64
func (*StandardOptions) GetUrlValue ¶
func (o *StandardOptions) GetUrlValue(fallback string) (result string)
func (*StandardOptions) IsBasicAuthEnabled ¶
func (o *StandardOptions) IsBasicAuthEnabled() bool
func (*StandardOptions) IsCsvOutputEnabled ¶
func (o *StandardOptions) IsCsvOutputEnabled() bool
func (*StandardOptions) IsDebugEnabled ¶
func (o *StandardOptions) IsDebugEnabled() bool
func (*StandardOptions) IsFormattedCsvEnabled ¶
func (o *StandardOptions) IsFormattedCsvEnabled() bool
func (*StandardOptions) IsFullOutputEnabled ¶
func (o *StandardOptions) IsFullOutputEnabled() bool
func (*StandardOptions) IsHeaderDisabled ¶
func (o *StandardOptions) IsHeaderDisabled() bool
func (*StandardOptions) IsHelpEnabled ¶
func (o *StandardOptions) IsHelpEnabled() bool
func (*StandardOptions) IsLocalCertsEnabled ¶
func (o *StandardOptions) IsLocalCertsEnabled() bool
func (*StandardOptions) IsNetDebugEnabled ¶
func (o *StandardOptions) IsNetDebugEnabled() bool
func (*StandardOptions) IsNoAuthEnabled ¶
func (o *StandardOptions) IsNoAuthEnabled() bool
func (*StandardOptions) IsNoRedirectEnabled ¶
func (o *StandardOptions) IsNoRedirectEnabled() bool
func (*StandardOptions) IsOutputBodyEnabled ¶
func (o *StandardOptions) IsOutputBodyEnabled() bool
func (*StandardOptions) IsOutputCookieEnabled ¶
func (o *StandardOptions) IsOutputCookieEnabled() bool
func (*StandardOptions) IsOutputHeaderEnabled ¶
func (o *StandardOptions) IsOutputHeaderEnabled() bool
func (*StandardOptions) IsOutputShortEnabled ¶
func (o *StandardOptions) IsOutputShortEnabled() bool
func (*StandardOptions) IsPrettyPrintEnabled ¶
func (o *StandardOptions) IsPrettyPrintEnabled() bool
func (*StandardOptions) IsQueryParamAuthEnabled ¶
func (o *StandardOptions) IsQueryParamAuthEnabled() bool
func (*StandardOptions) IsReconnectEnabled ¶
func (o *StandardOptions) IsReconnectEnabled() bool
func (*StandardOptions) IsSilentEnabled ¶
func (o *StandardOptions) IsSilentEnabled() bool
func (*StandardOptions) IsSkipCertValidationEnabled ¶
func (o *StandardOptions) IsSkipCertValidationEnabled() bool
func (*StandardOptions) IsVerboseEnabled ¶
func (o *StandardOptions) IsVerboseEnabled() bool
func (*StandardOptions) IsWarmingEnabled ¶
func (o *StandardOptions) IsWarmingEnabled() bool
func (StandardOptions) Set ¶
func (o StandardOptions) Set(options ...int) StandardOptions
Set -- Return a copy of the standard options with the specified boolean options set to true
type StartupOptions ¶
type StartupOptions struct {
DebugInit bool
InitFileName string
InitFileExt string
ScriptFileExt string
AbortOnExceptions bool
}
StartupOptions -- configuration available to the shell
func GetDefaultStartupOptions ¶
func GetDefaultStartupOptions() StartupOptions
GetDefaultStartupOptions return an interface to the options for the shell startup
type StringList ¶
type StringList struct {
Values []string
}
func (*StringList) Count ¶
func (sl *StringList) Count() int
func (*StringList) GetValues ¶
func (sl *StringList) GetValues() []string
func (*StringList) String ¶
func (sl *StringList) String() string
type SubstitutionFunction ¶
type SubstitutionFunction struct {
Name string
Group string
FunctionHelp string
FormatDescription string
Formats []SubstitutionItemHelp
OptionDescription string
Options []SubstitutionItemHelp
Function SubstitutionHandler
}
SubstitutionFunction -- a registration function for a handler and its help
type SubstitutionHandler ¶
type SubstitutionHandler func(cache interface{}, funcName string, fmt string, option string) (value string, data interface{})
SubstitutionHandler -- A handler returns a value for substitution given a function name. The handler may be given a fmt string and option string to guide the appropriate formating of data. The raw data is returned enabling re-use of the same data when the same key is used with a function in the same function group).
type SubstitutionItemHelp ¶
SubstitutionItemHelp -- Help strucsture for a format