vinxi: Index | Files | Directories

package vinxi

import ""


Package Files

server.go version.go vinxi.go


const Version = "0.1.0"

Version exposes the current package semantic version.


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
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.

type Metadata Uses

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 Uses

func NewMetadata() *Metadata

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

type Middleware Uses

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.

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

type Server Uses

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

    // 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 Uses

func NewServer(o ServerOptions) *Server

NewServer creates a new standard HTTP server.

func (*Server) Listen Uses

func (s *Server) Listen() error

Listen starts listening on network.

type ServerOptions Uses

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 Uses

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 Uses

func New() *Vinxi

New creates a new vinxi proxy layer with default fields.

func (*Vinxi) All Uses

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

All will register a pattern for any HTTP method.

func (*Vinxi) BindServer Uses

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

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

func (*Vinxi) Delete Uses

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

Delete will register a pattern for DELETE requests.

func (*Vinxi) Flush Uses

func (v *Vinxi) Flush()

Flush flushes all the middleware stack.

func (*Vinxi) Forward Uses

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

Forward defines the default URL to forward incoming traffic.

func (*Vinxi) Get Uses

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 Uses

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 Uses

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

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

func (*Vinxi) NewServer Uses

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

NewServer creates a new http.Server.

func (*Vinxi) Options Uses

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

Options will register a pattern for OPTIONS requests.

func (*Vinxi) Patch Uses

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

Patch will register a pattern for PATCH requests.

func (*Vinxi) Post Uses

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

Post will register a pattern for POST requests.

func (*Vinxi) Put Uses

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

Put will register a pattern for PUT requests.

func (*Vinxi) Route Uses

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 Uses

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

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

func (*Vinxi) SetForwader Uses

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

SetForwader sets the default final traffic forwarder.

func (*Vinxi) SetParent Uses

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

SetParent sets a parent middleware layer.

func (*Vinxi) Use Uses

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

Use attaches a new middleware handler for incoming HTTP traffic.

func (*Vinxi) UseFinalHandler Uses

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

UseFinalHandler uses a new middleware handler function as final handler.

func (*Vinxi) UsePhase Uses

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

UsePhase attaches a new middleware handler to a specific phase.


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

Package vinxi imports 11 packages (graph). Updated 2017-12-07. Refresh now. Tools for package owners.