vinxi

package module
v0.0.0-...-3f1871c Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: MIT Imports: 11 Imported by: 0

README

Build Status GitHub release GoDoc Coverage Status Go Report Card License Status

Note: vinxi is deprecated and not longer actively maintained.

Visit vinxi's website to get started.

Installation

go get -u gopkg.in/vinxi/vinxi.v0

API

See godoc reference for detailed API documentation.

Examples

See examples directory.

Command-line interface

See vinxictl for command-line usage.

Development

Clone the repository:

git clone https://github.com/vinxi/vinxi.git && cd vinxi

Create subpackages symbolic links in $GOPATH:

make link

Lint, format and run tests:

make 

License

Mixed Apache License 2.0 and MIT License (see file header for details).

Documentation

Index

Constants

View Source
const Version = "0.1.0"

Version exposes the current package semantic version.

Variables

View Source
var (
	// DefaultPort stores the default TCP port to listen.
	DefaultPort = 8080

	// DefaultReadTimeout defines the maximum timeout for request read.
	DefaultReadTimeout = 60

	// DefaultWriteTimeout defines the maximum timeout for response write.
	DefaultWriteTimeout = 60
)
View Source
var DefaultForwarder, _ = forward.New(forward.PassHostHeader(true))

DefaultForwarder stores the default http.Handler to be used to forward the traffic. By default the proxy will reply with 502 Bad Gateway if no custom forwarder is defined.

Functions

This section is empty.

Types

type Metadata

type Metadata struct {
	// ID stores the unique instance identifier.
	ID string `json:"id"`
	// Name stores the vinxi instance name identifier.
	Name string `json:"name,omitempty"`
	// Description stores the vinxi instance friendly description.
	// This field is optional.
	Description string `json:"description,omitempty"`
	// Hostname stores the current hostname where vinxi is running.
	// This is platform specific and could be empty.
	Hostname string `json:"hostname,omitempty"`
	// Platform stores the current runtime platform.
	Platform string `json:"platform,omitempty"`
	// ServerOptions stores the http.Server init options for further reference.
	ServerOptions ServerOptions `json:"server,omitempty"`
}

Metadata represents the vinxi instance metadata fields used to store and retrieve generic and human friendly proxy information, mostly useful for external management.

func NewMetadata

func NewMetadata() *Metadata

NewMetadata creates a new vinxi instance metadata instance with default fields based on the runtime environment.

type Middleware

type Middleware interface {
	// Use is used to register one or multiple middleware handlers.
	Use(...interface{}) Middleware
	// UsePhase is used to register one or multiple middleware
	// handlers for a specific middleware phase.
	UsePhase(string, ...interface{}) Middleware
	// UseFinalHandler is used to register the final request handler
	// usually to define the error or forward handlers.
	UseFinalHandler(http.Handler) Middleware
	// SetParent allows hierarchical middleware inheritance.
	SetParent(layer.Middleware)
}

Middleware defines the required interface implemented by public middleware capable entities in the vinxi ecosystem.

type Server

type Server struct {
	// Vinxi stores the Vinxi layer instance.
	*Vinxi

	// Server stores the http.Server instance.
	Server *http.Server

	// Options stores the server start options.
	Options ServerOptions
}

Server represents a simple wrapper around http.Server for better convenience and easy set up using Vinxi.

func NewServer

func NewServer(o ServerOptions) *Server

NewServer creates a new standard HTTP server.

func (*Server) Listen

func (s *Server) Listen() error

Listen starts listening on network.

type ServerOptions

type ServerOptions struct {
	Port         int    `json:"port,omitempty"`
	ReadTimeout  int    `json:"readTimeout"`
	WriteTimeout int    `json:"writeTimeout"`
	Addr         string `json:"address"`
	Forward      string `json:"forward,omitempty"`
	CertFile     string `json:"certificate,omitempty"`
	KeyFile      string `json:"-"`
}

ServerOptions represents the supported server options.

type Vinxi

type Vinxi struct {
	// Medata stores the vinxi instance specific metadata.
	Metadata *Metadata
	// Layer stores the proxy level middleware layer.
	Layer *layer.Layer
	// Router stores the built-in router.
	Router *router.Router
}

Vinxi represents the vinxi proxy layer.

func New

func New() *Vinxi

New creates a new vinxi proxy layer with default fields.

func (*Vinxi) All

func (v *Vinxi) All(path string) *router.Route

All will register a pattern for any HTTP method.

func (*Vinxi) BindServer

func (v *Vinxi) BindServer(server *http.Server)

BindServer binds the vinxi HTTP handler to the given http.Server.

func (*Vinxi) Delete

func (v *Vinxi) Delete(path string) *router.Route

Delete will register a pattern for DELETE requests.

func (*Vinxi) Flush

func (v *Vinxi) Flush()

Flush flushes all the middleware stack.

func (*Vinxi) Forward

func (v *Vinxi) Forward(uri string) *Vinxi

Forward defines the default URL to forward incoming traffic.

func (*Vinxi) Get

func (v *Vinxi) Get(path string) *router.Route

Get will register a pattern for GET requests. It also registers pat for HEAD requests. If this needs to be overridden, use Head before Get with pat.

func (*Vinxi) ListenAndServe

func (v *Vinxi) ListenAndServe(opts ServerOptions) (*Server, error)

ListenAndServe creates a new http.Server and starts listening on the network based on the given server options.

func (*Vinxi) Mux

func (v *Vinxi) Mux(matchers ...mux.Matcher) *mux.Mux

Mux creates a new multiplexer based on the given matcher functions.

func (*Vinxi) NewServer

func (v *Vinxi) NewServer(opts ServerOptions) *Server

NewServer creates a new http.Server.

func (*Vinxi) Options

func (v *Vinxi) Options(path string) *router.Route

Options will register a pattern for OPTIONS requests.

func (*Vinxi) Patch

func (v *Vinxi) Patch(path string) *router.Route

Patch will register a pattern for PATCH requests.

func (*Vinxi) Post

func (v *Vinxi) Post(path string) *router.Route

Post will register a pattern for POST requests.

func (*Vinxi) Put

func (v *Vinxi) Put(path string) *router.Route

Put will register a pattern for PUT requests.

func (*Vinxi) Route

func (v *Vinxi) Route(method, path string) *router.Route

Route will register a new route for the given pattern and HTTP method.

func (*Vinxi) ServeHTTP

func (v *Vinxi) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the required http.Handler interface to handle incoming traffic.

func (*Vinxi) SetForwader

func (v *Vinxi) SetForwader(fn http.Handler) *Vinxi

SetForwader sets the default final traffic forwarder.

func (*Vinxi) SetParent

func (v *Vinxi) SetParent(parent layer.Middleware)

SetParent sets a parent middleware layer.

func (*Vinxi) Use

func (v *Vinxi) Use(handler ...interface{}) *Vinxi

Use attaches a new middleware handler for incoming HTTP traffic.

func (*Vinxi) UseFinalHandler

func (v *Vinxi) UseFinalHandler(fn http.Handler) *Vinxi

UseFinalHandler uses a new middleware handler function as final handler.

func (*Vinxi) UsePhase

func (v *Vinxi) UsePhase(phase string, handler ...interface{}) *Vinxi

UsePhase attaches a new middleware handler to a specific phase.

Directories

Path Synopsis
_examples
mux
Package context implements a simple request-aware HTTP context designed to be used via middleware layer to share polymorfic data.
Package context implements a simple request-aware HTTP context designed to be used via middleware layer to share polymorfic data.
Package forward implements http handler that forwards requests to remote server and serves back the response.
Package forward implements http handler that forwards requests to remote server and serves back the response.
Package layer implements a simple HTTP server middleware layer used internally by vinxi to compose and trigger the middleware chain.
Package layer implements a simple HTTP server middleware layer used internally by vinxi to compose and trigger the middleware chain.
mux
Package mux implements an HTTP domain-specific traffic multiplexer with built-in matchers and features for easy plugin composition and activable logic.
Package mux implements an HTTP domain-specific traffic multiplexer with built-in matchers and features for easy plugin composition and activable logic.
Package router implements a simple URL pattern muxer router with hierarchical middleware layer.
Package router implements a simple URL pattern muxer router with hierarchical middleware layer.

Jump to

Keyboard shortcuts

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