helpers

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultEpsilon = 0.000000001
)
View Source
const (
	XrfKeySize = 16
)

Variables

View Source
var (
	FloatMinNormal = math.Float64frombits(0x00800000)
)
View Source
var GlobalBufferPool = NewBufferPool()
View Source
var (
	XrfKeyChars = []rune("abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789")
)

Functions

func AppendToBaseName added in v0.8.0

func AppendToBaseName(filePath string, strs ...string) string

func FlattenMultiError

func FlattenMultiError(mErr *multierror.Error) error

FlattenMultiError return nil or original error if multierror does not have more than one error

func GenerateXrfKey added in v0.14.5

func GenerateXrfKey(rnd Randomizer) string

func GetFileNameFromHTTPHeader added in v0.8.0

func GetFileNameFromHTTPHeader(headers http.Header) (string, error)

GetFileNameFromHTTPHeader returns the first filename found in content-disposition header.

func HasDeprecatedFields added in v0.6.8

func HasDeprecatedFields(rawJson []byte, deprecatedPaths []string) error

HasDeprecatedFields check json if keys exist at provided paths, if any exist report error

func IsContextTriggered

func IsContextTriggered(ctx context.Context) bool

IsContextTriggered check if context is "done"

func NearlyEqual added in v0.11.5

func NearlyEqual(a, b float64) bool

func NearlyEqualEpsilon added in v0.11.5

func NearlyEqualEpsilon(a, b float64, epsilon float64) bool

NearlyEqual float points covering some edge cases as per https://floating-point-gui.de/errors/comparison/#look-out-for-edge-cases

func RecoverWithError

func RecoverWithError(panicErr *error)

RecoverWithError recovers from panic and sets error to panicErr

func RecoverWithErrorFunc added in v0.6.17

func RecoverWithErrorFunc(f func()) error

RecoverWithErrorFunc recovers from panic and returns panic error

func ToValidWindowsFileName added in v0.8.0

func ToValidWindowsFileName(fileName string) string

func TrueCause added in v0.5.7

func TrueCause(err error) error

TrueCause of error, in the case of a multi error, the first error in list will be used

func WaitFor

func WaitFor(ctx context.Context, duration time.Duration)

WaitFor context or timeout

func WriteToFile added in v0.8.0

func WriteToFile(filePath string, data []byte) error

WriteToFile writes data to file defined by filePath

Types

type Buffer

type Buffer struct {
	B     *strings.Builder
	Error error
}

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates and initializes a new string Buffer.

func (*Buffer) Reset

func (buffer *Buffer) Reset()

Reset resets the buffer to be empty,

func (*Buffer) String

func (buffer *Buffer) String() string

String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".

func (*Buffer) WriteByte

func (buffer *Buffer) WriteByte(c byte)

WriteByte appends the byte c to the buffer, growing the buffer as needed.

func (*Buffer) WriteBytes

func (buffer *Buffer) WriteBytes(p []byte)

Write bytes to buffer, errors written to stderr

func (*Buffer) WriteRune

func (buffer *Buffer) WriteRune(r rune)

WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, errors written to stderr

func (*Buffer) WriteString

func (buffer *Buffer) WriteString(s string)

WriteString to buffer, errors written to stderr

func (*Buffer) WriteTo

func (buffer *Buffer) WriteTo(w io.Writer)

WriteTo writes data to w until the buffer is drained or an error occurs., errors written to stderr

type BufferPool added in v0.6.21

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

func NewBufferPool added in v0.6.21

func NewBufferPool() *BufferPool

func (*BufferPool) Get added in v0.6.21

func (bp *BufferPool) Get() *bytes.Buffer

func (*BufferPool) Put added in v0.6.21

func (bp *BufferPool) Put(buf *bytes.Buffer)

type DataPath added in v0.6.8

type DataPath string

DataPath string which can be return as substring splitted on / (slash)

func NewDataPath added in v0.6.8

func NewDataPath(path string) DataPath

NewDataPath new instance

func (DataPath) Contains added in v0.6.8

func (path DataPath) Contains(val string) bool

Contains Check if path contains value

func (DataPath) Lookup added in v0.6.8

func (path DataPath) Lookup(data json.RawMessage) (json.RawMessage, error)

Lookup object in path, if data found is of type string it will be quoted with ""

func (DataPath) LookupMulti added in v0.6.8

func (path DataPath) LookupMulti(data json.RawMessage, separator string) ([]json.RawMessage, error)

LookupMulti objects with subpaths under an array in a path

func (DataPath) LookupNoQuotes added in v0.6.8

func (path DataPath) LookupNoQuotes(data json.RawMessage) (json.RawMessage, error)

LookupNoQuotes object in path, data of type string will not be quoted

func (DataPath) Set added in v0.6.15

func (path DataPath) Set(data []byte, newValue []byte) ([]byte, error)

Set look object in path and set to new object

func (*DataPath) String added in v0.6.8

func (path *DataPath) String() string

String string representation of datapath

type DistributionSettings

type DistributionSettings struct {
	// Type of timer delay
	Type DistributionType `json:"type" displayname:"Distribution type" doc-key:"thinktime.type"`
	// Delay static delay when using static timer delay
	Delay float64 `json:"delay,omitempty" displayname:"Static delay" doc-key:"thinktime.delay"`
	// Mean value
	Mean float64 `json:"mean,omitempty" displayname:"Mean value" doc-key:"thinktime.mean"`
	// Deviation value
	Deviation float64 `json:"dev,omitempty" displayname:"Deviation value" doc-key:"thinktime.dev"`
}

DistributionSettings think time settings

func (DistributionSettings) GetActionInfo

func (settings DistributionSettings) GetActionInfo() string

GetActionInfo get information for action details logging

func (DistributionSettings) GetMax

func (settings DistributionSettings) GetMax() (float64, error)

GetMax value

func (DistributionSettings) GetMin

func (settings DistributionSettings) GetMin() (float64, error)

GetMin value

func (DistributionSettings) RandDuration added in v0.4.11

func (settings DistributionSettings) RandDuration(rnd Randomizer) (time.Duration, error)

RandDuration returns a random duration

func (DistributionSettings) Validate

func (settings DistributionSettings) Validate() ([]string, error)

Validate DistributionSettings

type DistributionType

type DistributionType int

DistributionType type of distribution

const (
	// StaticDistribution fixed distribution
	StaticDistribution DistributionType = iota
	// UniformDistribution uniform distribution, defined by "mean" and "dev"
	UniformDistribution
)

func (DistributionType) GetEnumMap

func (value DistributionType) GetEnumMap() *enummap.EnumMap

GetEnumMap of DistributionType

func (DistributionType) MarshalJSON

func (value DistributionType) MarshalJSON() ([]byte, error)

MarshalJSON marshal ThinkTime type

func (*DistributionType) UnmarshalJSON

func (value *DistributionType) UnmarshalJSON(arg []byte) error

UnmarshalJSON unmarshal DistributionType

type FuzzyBool added in v0.17.18

type FuzzyBool bool

FuzzyBool resolves boolean sent as strings, integers, float64 or boolean, json unmarshal defaults to true

func (*FuzzyBool) AsBool added in v0.17.18

func (fb *FuzzyBool) AsBool() bool

AsBool returns bool representation of StringBool

func (*FuzzyBool) UnmarshalJSON added in v0.17.18

func (fb *FuzzyBool) UnmarshalJSON(arg []byte) error

UnmarshalJSON FuzzyBool

type FuzzyInt added in v0.18.2

type FuzzyInt int

FuzzyInt resolves integer sent as string, integer or float64

func (*FuzzyInt) UnmarshalJSON added in v0.18.2

func (fi *FuzzyInt) UnmarshalJSON(arg []byte) error

type NoDataFound added in v0.6.8

type NoDataFound string

NoDataFound no data found in path

func (NoDataFound) Error added in v0.6.8

func (err NoDataFound) Error() string

Error no data found in data path

type NoStepsError added in v0.6.8

type NoStepsError string

NoStepsError no steps to take in data path

func (NoStepsError) Error added in v0.6.8

func (err NoStepsError) Error() string

Error no steps in data path

type Params

type Params map[string]string

Params map with URL parameters

func (Params) String

func (params Params) String() string

String returns parameters as string with the format ?param1=val1&param2=val2, parameter order is not guaranteed

type Password added in v0.15.5

type Password string

Password

func (*Password) MarshalJSON added in v0.15.5

func (passwd *Password) MarshalJSON() ([]byte, error)

MarshalJSON marshal password to json: replace with ***

func (*Password) UnmarshalJSON added in v0.15.5

func (passwd *Password) UnmarshalJSON(arg []byte) error

UnmarshalJSON unmarshal password from json

type Randomizer added in v0.4.11

type Randomizer interface {
	Rand(max int) int
	RandWeightedInt(weights []int) (int, error)
	RandIntPos(ints []int) (int, int, error)
	RandDuration(minDuration, maxDuration time.Duration) (time.Duration, error)
	Reset(instance, session uint64, onlyinstanceSeed bool)
	RandRune(runes []rune) rune
	// Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
	Float64() float64
}

type RowFile

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

RowFile path to file on disc to read into memory

func NewRowFile

func NewRowFile(filepath string) (RowFile, error)

NewRowFile reads rows from file path into memory

func (*RowFile) IsEmpty

func (file *RowFile) IsEmpty() bool

IsEmpty reports true if a filepath is not set

func (RowFile) MarshalJSON

func (file RowFile) MarshalJSON() ([]byte, error)

MarshalJSON marshal filepath to JSON

func (*RowFile) PurgeRows added in v0.11.4

func (file *RowFile) PurgeRows()

PurgeRows from memory

func (*RowFile) Rows

func (file *RowFile) Rows() []string

Rows in memory from file, to read into memory, either ReadRows or UnmarshalJSON needs to have been called

func (RowFile) String

func (file RowFile) String() string

String implements stringer interface

func (RowFile) TreatAs

func (file RowFile) TreatAs() string

func (*RowFile) UnmarshalJSON

func (file *RowFile) UnmarshalJSON(arg []byte) error

UnmarshalJSON reads file from filepath into memory

type TimeDuration

type TimeDuration time.Duration

func (TimeDuration) MarshalJSON

func (duration TimeDuration) MarshalJSON() ([]byte, error)

MarshalJSON marshal time buffer duration to JSON

func (*TimeDuration) UnmarshalJSON

func (duration *TimeDuration) UnmarshalJSON(arg []byte) error

UnmarshalJSON unmarshal time buffer duration from JSON

type TreatAs

type TreatAs interface {
	/*
		Supported types:
			String
			Int
			Float
			Enum
			Bool
			Slice
			SliceElement
			StringMap
			StringMapElement
	*/
	TreatAs() string
}

Implement this interface to override the type a struct is treated as by the GUI

type UniqueInts added in v0.5.3

type UniqueInts map[int]struct{}

func (*UniqueInts) AddValue added in v0.5.3

func (u *UniqueInts) AddValue(v int)

AddValue to unique list

func (*UniqueInts) Array added in v0.5.3

func (u *UniqueInts) Array() []int

Array of unique integers

func (*UniqueInts) HasValue added in v0.5.3

func (u *UniqueInts) HasValue(v int) bool

HasValue test if collection includes value

Jump to

Keyboard shortcuts

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