cfg

package
v0.0.0-...-76f5f5b Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Defs []*MatchDef            `json:"pattern_list" yaml:"pattern_list"`
	Vars map[string]interface{} `json:"vars" yaml:"vars"`
}

Config represents an imPOSTer configuration. A set of rule expressions can be defined dy Defs field.

func ReadConfig

func ReadConfig(configFile string) (*Config, error)

ReadConfig takes a path as an input and parses its content to build the imPOSTer configuration.

type MatchDef

type MatchDef struct {
	RuleExpression string        `json:"rule_expression" yaml:"rule_expression"`
	Latency        time.Duration `json:"latency" yaml:"latency"`
	Response       interface{}   `json:"response" yaml:"response"`
}

MatchDef represents a single rule expression. The RuleExpression field wraps a boolean expression every incoming HTTP request is matched against. How a matching rule expression should be managed is defined by the Response object.

func (*MatchDef) Validate

func (def *MatchDef) Validate(parse functions.ExpressionParser, vars map[string]interface{}) []string

Validate method parses the current expression trying to catch potential evaluation errors. An empty array is returned whether no errors were found.

type MatchRsp

type MatchRsp struct {
	Body       string                 `mapstructure:"body"`
	Headers    map[string]interface{} `mapstructure:"headers"`
	StatusCode string                 `mapstructure:"status_code"`
}

MatchRsp is the fully structured version of a Response object. Body represents the payload to be returned and it can be an expression as well. Headers is a collection of HTTP headers to be returned and each entry can be an expression. StatusCode represents the resulting HTTP status code and it MUST be an expression:

rsp := MatchRsp{Body: "some content", StatusCode: `${200}`}

func (*MatchRsp) ParseHeaders

func (rsp *MatchRsp) ParseHeaders(parse functions.ExpressionParser) (map[string]functions.Expression, error)

ParseHeaders evaluates any HTTP header and returns an expression for each of them. It returns an error in case of evaluation failures.

func (*MatchRsp) ParseStatusCode

func (rsp *MatchRsp) ParseStatusCode(parse functions.ExpressionParser) (functions.Expression, error)

ParseStatusCode evaluates the resulting status code expression to an integer. It returns an error in case of evaluation failures.

Jump to

Keyboard shortcuts

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