muxy

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: MIT Imports: 1 Imported by: 12

Documentation

Overview

Package muxy contains the main interfaces used throughout Muxy: Context, Middleware and Proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Request contains a reference to the HTTP Request
	// if it's an HTTP proxied event.
	// It may be mutated by prior and future middlewares/plugins
	Request *http.Request

	// Response contains a reference to the HTTP Response
	// if it's an HTTP proxied event.
	// It may be mutated by prior and future middlewares/plugins
	Response *http.Response

	// ResponseWriter for the current HTTP session if it exists.
	ResponseWriter http.ResponseWriter

	// Bytes contains the current message for TCP sessions.
	Bytes []byte
}

Context is the request context given to Middlewares and Symptoms.

type Middleware

type Middleware interface {
	// Setup is called when the plugin is registered
	Setup()

	// HandleEvent takes a ProxyEvent and acts on the information provided
	HandleEvent(event ProxyEvent, ctx *Context)

	// Teardown is used to cleanup any resources on plugin destray
	Teardown()
}

Middleware is a plugin that intercepts requests and injects chaos Middleware's are executed in stacked order before or after a Middleware, and are perfect for jobs like instrumentation. They are given a read/write copy of the runtime context and are executed synchronously.

Middleware's are registered via a plugin factory e.g.

func init() {
  muxy.PluginFactories.Register(NewMiddlewarex, "sypmtomname")
}

Where NewMiddlewarex is a func that returns a interface{} (Middleware) when called

type Proxy

type Proxy interface {
	Setup([]Middleware)
	Proxy()
	Teardown()
}

Proxy is the interface for a Proxy plugin

type ProxyEvent

type ProxyEvent int

ProxyEvent is the event set to a proxy

const (
	// EventPreDispatch is the event sent prior to dispatching a request
	EventPreDispatch ProxyEvent = iota

	// EventPostDispatch is the event sent directly after dispatching a request
	EventPostDispatch
)

Jump to

Keyboard shortcuts

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