Documentation ¶
Index ¶
- Constants
- Variables
- type Metadata
- type Middleware
- type Server
- type ServerOptions
- type Vinxi
- func (v *Vinxi) All(path string) *router.Route
- func (v *Vinxi) BindServer(server *http.Server)
- func (v *Vinxi) Delete(path string) *router.Route
- func (v *Vinxi) Flush()
- func (v *Vinxi) Forward(uri string) *Vinxi
- func (v *Vinxi) Get(path string) *router.Route
- func (v *Vinxi) ListenAndServe(opts ServerOptions) (*Server, error)
- func (v *Vinxi) Mux(matchers ...mux.Matcher) *mux.Mux
- func (v *Vinxi) NewServer(opts ServerOptions) *Server
- func (v *Vinxi) Options(path string) *router.Route
- func (v *Vinxi) Patch(path string) *router.Route
- func (v *Vinxi) Post(path string) *router.Route
- func (v *Vinxi) Put(path string) *router.Route
- func (v *Vinxi) Route(method, path string) *router.Route
- func (v *Vinxi) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (v *Vinxi) SetForwader(fn http.Handler) *Vinxi
- func (v *Vinxi) SetParent(parent layer.Middleware)
- func (v *Vinxi) Use(handler ...interface{}) *Vinxi
- func (v *Vinxi) UseFinalHandler(fn http.Handler) *Vinxi
- func (v *Vinxi) UsePhase(phase string, handler ...interface{}) *Vinxi
Constants ¶
const Version = "0.1.0"
Version exposes the current package semantic version.
Variables ¶
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.
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.
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 (*Vinxi) BindServer ¶
BindServer binds the vinxi HTTP handler to the given http.Server.
func (*Vinxi) Get ¶
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) NewServer ¶
func (v *Vinxi) NewServer(opts ServerOptions) *Server
NewServer creates a new http.Server.
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 ¶
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) UseFinalHandler ¶
UseFinalHandler uses a new middleware handler function as final handler.
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
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. |
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. |