Documentation
¶
Overview ¶
Package httpsim provides an HTTP simulator middleware that simplifies conditionally adding artificial delays and overwriting responses matching requests by path, headers and query parameters using glob expressions.
Index ¶
Constants ¶
const DefaultRand defaultRand = 1
DefaultRand is the default ChaCha8 randomness provider based on a crypto-random seed.
const DefaultSleep defaultSleep = 1
DefaultSleep is the default system sleep `time.Sleep`.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
func LoadConfig ¶
LoadConfig loads config from arbitrary reader.
func LoadConfigFile ¶
LoadConfigFile loads config from file.
type CtxInfo ¶
CtxInfo is written to the request context after handling.
func CtxInfoValue ¶
CtxInfoValue gets the `CtxInfo` from ctx.
type CtxKey ¶
type CtxKey int8
CtxKey is a context.Context key type.
const CtxKeyInfo CtxKey = 1
CtxKeyInfo is used by CtxInfoValue to get `CtxInfo` from `context.Context`.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements the http.Handler interface.
func NewMiddleware ¶
func NewMiddleware( next http.Handler, c config.Config, sleeper Sleeper, rnd RandProvider, ) *Middleware
NewMiddleware creates a new middleware instance. Use `DefaultSleep` for sleeper (other implementations of Sleeper should only be used for testing purposes). Use `DefaultRand` for rnd if not sure.
func (*Middleware) ServeHTTP ¶
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*Middleware) SetConfig ¶
func (m *Middleware) SetConfig(c config.Config)
SetConfig changes the configuration of the middleware. SetConfig is safe for concurrent use at runtime.
type RandProvider ¶
type RandProvider interface {
// Dur returns a random duration within the given min and max range.
Dur(min, max time.Duration) time.Duration
// Bool returns a random boolean value.
Bool() bool
}
RandProvider is a random values generator.