config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldMethod         = "method"
	FieldURL            = "url"
	FieldHeader         = "header"
	FieldBody           = "body"
	FieldRequests       = "requests"
	FieldConcurrency    = "concurrency"
	FieldInterval       = "interval"
	FieldRequestTimeout = "requestTimeout"
	FieldGlobalTimeout  = "globalTimeout"
	FieldOut            = "out"
	FieldSilent         = "silent"
	FieldTemplate       = "template"
)

Variables

View Source
var FieldsUsage = map[string]string{
	FieldMethod:         "HTTP request method",
	FieldURL:            "HTTP request url",
	FieldHeader:         "HTTP request header",
	FieldBody:           "HTTP request body",
	FieldRequests:       "Number of requests to run, use duration as exit condition if omitted",
	FieldConcurrency:    "Number of connections to run concurrently",
	FieldInterval:       "Minimum duration between two non concurrent requests",
	FieldRequestTimeout: "Timeout for each HTTP request",
	FieldGlobalTimeout:  "Max duration of test",
	FieldOut:            "Output destination (benchttp,json,stdout)",
	FieldSilent:         "Silent mode (no write to stdout)",
	FieldTemplate:       "Output template",
}

FieldsUsage is a record of all available config fields and their usage.

Functions

func IsField

func IsField(v string) bool

func IsOutput

func IsOutput(v string) bool

Types

type Body

type Body struct {
	Type    string
	Content []byte
}

Body represents a request body associated with a type. The type affects the way the content is processed. If Type == "file", Content is read as a filepath to be resolved. If Type == "raw", Content is attached as-is.

Note: only "raw" is supported at the moment.

func NewBody

func NewBody(typ, content string) Body

NewBody returns a Body initialized with the given type and content. For now, the only valid value for type is "raw".

type Global

type Global struct {
	Request Request
	Runner  Runner
	Output  Output
}

Global represents the global configuration of the runner. It must be validated using Global.Validate before usage.

func Default

func Default() Global

Default returns a default config that is safe to use.

func (Global) Override

func (cfg Global) Override(c Global, fields ...string) Global

Override returns a new Config based on cfg with overridden values from c. Only fields specified in options are replaced. Accepted options are limited to existing Fields, other values are silently ignored.

func (Global) String

func (cfg Global) String() string

String returns an indented JSON representation of Config for debugging purposes.

func (Global) Validate

func (cfg Global) Validate() error

Validate returns a non-nil InvalidConfigError if any of its fields does not meet the requirements.

type InvalidConfigError added in v1.0.0

type InvalidConfigError struct {
	Errors []error
}

InvalidConfigError is the errors returned by Global.Validate when values are missing or invalid.

func (*InvalidConfigError) Error added in v1.0.0

func (e *InvalidConfigError) Error() string

Error returns the joined errors of InvalidConfigError as a string.

type Output

type Output struct {
	Out      []OutputStrategy
	Silent   bool
	Template string
}

Output contains options relative to the output.

func (Output) HasStrategy added in v1.0.0

func (o Output) HasStrategy(s OutputStrategy) bool

type OutputStrategy

type OutputStrategy string
const (
	OutputBenchttp OutputStrategy = "benchttp"
	OutputJSON     OutputStrategy = "json"
	OutputStdout   OutputStrategy = "stdout"
)

type Request

type Request struct {
	Method string
	URL    *url.URL
	Header http.Header
	Body   Body
}

Request contains the confing options relative to a single request.

func (Request) Value

func (r Request) Value() (*http.Request, error)

Value generates a *http.Request based on Request and returns it or any non-nil error that occurred.

func (Request) WithURL

func (r Request) WithURL(rawURL string) Request

WithURL sets the current Request with the parsed *url.URL from rawURL and returns it. Any errors is discarded as a Config can be invalid until Config.Validate is called. The url is always non-nil.

type Runner

type Runner struct {
	Requests       int
	Concurrency    int
	Interval       time.Duration
	RequestTimeout time.Duration
	GlobalTimeout  time.Duration
}

Runner contains options relative to the runner.

Jump to

Keyboard shortcuts

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