manager

package
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, MIT Imports: 18 Imported by: 0

README

manager Build Status GoDoc Coverage Status

manager package implements a programmatic and HTTP API mangement layer for vinxi proxies.

Installation

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

API

See godoc reference.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

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

	// DefaultSecurePort stores the default TCP port to listen for secure only connections.
	DefaultSecurePort = 8443

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

	// DefaultWriteTimeout defines the maximum timeout for response write.
	DefaultWriteTimeout = 60
)

Functions

func Listen

func Listen(server *http.Server, opts ServerOptions) error

Listen starts listening on the network.

func NewServer

func NewServer(o ServerOptions) *http.Server

NewServer creates a new admin HTTP server.

Types

type Context

type Context struct {
	Manager      *Manager
	Scope        *Scope
	Instance     *Instance
	AdminPlugins *plugin.Layer
	Request      *http.Request
	Response     http.ResponseWriter
	Rule         rule.Rule
	Plugin       plugin.Plugin
}

Context is used to share request context entities across controllers.

func (*Context) ParseBody

func (c *Context) ParseBody(bind interface{}) error

ParseBody parses the body.

func (*Context) Send

func (c *Context) Send(status int, data interface{})

Send is used to serialize and write the response as JSON with custom status code.

func (*Context) SendError

func (c *Context) SendError(status int, message string)

SendError replies with an custom error message and 500 as status code.

func (*Context) SendNoContent

func (c *Context) SendNoContent()

SendNoContent replies with 204 status code.

func (*Context) SendNotFound

func (c *Context) SendNotFound(message string)

SendNotFound replies with 404 status code and custom message.

func (*Context) SendOk

func (c *Context) SendOk(data interface{})

SendOk is used to serialize and write the response as JSON.

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance represents the manager instance level.

func NewInstance

func NewInstance(name, description string, proxy *vinxi.Vinxi) *Instance

NewInstance creates a new vinxi manager instance.

func (*Instance) GetScope

func (i *Instance) GetScope(name string) *Scope

GetScope finds and return a registered scope instance.

func (*Instance) HandleHTTP

func (i *Instance) HandleHTTP(w http.ResponseWriter, r *http.Request, next http.Handler)

HandleHTTP is triggered by the vinxi middleware layer on incoming HTTP request.

func (*Instance) ID

func (i *Instance) ID() string

ID returns the instance unique identifier.

func (*Instance) Metadata

func (i *Instance) Metadata() *vinxi.Metadata

Metadata returns the vinxi instance metadata struct.

func (*Instance) NewDefaultScope

func (i *Instance) NewDefaultScope(rules ...rule.Rule) *Scope

NewDefaultScope creates a new default scope.

func (*Instance) NewScope

func (i *Instance) NewScope(name, description string) *Scope

NewScope creates a new scope based on the given name and optional description.

func (*Instance) RemoveScope

func (i *Instance) RemoveScope(name string) bool

RemoveScope removes a registered scope. Returns false if the scope cannot be found.

func (*Instance) Scopes

func (i *Instance) Scopes() []*Scope

Scopes returns the list of registered scopes.

func (*Instance) UseScope

func (i *Instance) UseScope(scopes ...*Scope)

UseScope registers one or multiple scopes at instance level.

type JSONInstance

type JSONInstance struct {
	Info   *vinxi.Metadata `json:"info"`
	Scopes []JSONScope     `json:"scopes"`
}

JSONInstance represents the Instance entity for JSON serialization.

type JSONPlugin

type JSONPlugin struct {
	ID          string        `json:"id"`
	Name        string        `json:"name,omitempty"`
	Description string        `json:"description,omitempty"`
	Enabled     bool          `json:"enabled,omitempty"`
	Config      config.Config `json:"config,omitempty"`
	Metadata    config.Config `json:"metadata,omitempty"`
}

JSONPlugin represents the Plugin entity for JSON serialization.

type JSONRule

type JSONRule struct {
	ID          string        `json:"id"`
	Name        string        `json:"name,omitempty"`
	Description string        `json:"description,omitempty"`
	Config      config.Config `json:"config,omitempty"`
	Metadata    config.Config `json:"metadata,omitempty"`
}

JSONRule represents the Rule entity for JSON serialization.

type JSONScope

type JSONScope struct {
	ID      string       `json:"id"`
	Name    string       `json:"name,omitempty"`
	Rules   []JSONRule   `json:"rules"`
	Plugins []JSONPlugin `json:"plugins"`
}

JSONScope represents the scope entity for JSON serialization.

type Manager

type Manager struct {

	// AdminPlugins stores the HTTP admin server plugins.
	AdminPlugins *plugin.Layer
	// Plugins stores the global plugin layer.
	Plugins *plugin.Layer
	// Server stores the HTTP server used for the admin.
	Server *http.Server
	// Layer stores the manager internal middleware layer.
	Layer *layer.Layer
	// Router stores the manager HTTP router for the admin server.
	Router *httprouter.Router
	// contains filtered or unexported fields
}

Manager represents the vinxi proxy admin manager.

func Manage

func Manage(name, description string, proxy *vinxi.Vinxi) *Manager

Manage creates a new empty manage and starts managing the given vinxi proxy instance.

func New

func New() *Manager

New creates a new manager able to manage and configure multiple vinxi proxy instance.

func (*Manager) GetInstance

func (m *Manager) GetInstance(name string) *Instance

GetInstance finds and returns a vinxi managed instance.

func (*Manager) GetPlugin

func (m *Manager) GetPlugin(name string) plugin.Plugin

GetPlugin finds and returns a plugin by its ID or name.

func (*Manager) GetScope

func (m *Manager) GetScope(name string) *Scope

GetScope finds and returns a vinxi managed instance.

func (*Manager) HandleHTTP

func (m *Manager) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler)

HandleHTTP is triggered by the vinxi middleware layer on incoming HTTP request.

func (*Manager) Instances

func (m *Manager) Instances() []*Instance

Instances returns the registered vinxi instances in the manager.

func (*Manager) ListenAndServe

func (m *Manager) ListenAndServe(opts ServerOptions) (*http.Server, error)

ListenAndServe creates a new admin HTTP server and starts listening on the network based on the given server options.

func (*Manager) Manage

func (m *Manager) Manage(name, description string, proxy *vinxi.Vinxi) *Instance

Manage adds a new vinxi proxy instance to be managed by the current manager instance.

func (*Manager) NewDefaultScope

func (m *Manager) NewDefaultScope(rules ...rule.Rule) *Scope

NewDefaultScope creates a new default scope.

func (*Manager) NewScope

func (m *Manager) NewScope(name, description string) *Scope

NewScope creates a new scope based on the given name and optional description.

func (*Manager) RemoveInstance

func (m *Manager) RemoveInstance(name string) bool

RemoveInstance removes a registered vinxi instance. Returns false if the instance cannot be found.

func (*Manager) RemovePlugin

func (m *Manager) RemovePlugin(id string) bool

RemovePlugin removes a plugin by its ID.

func (*Manager) RemoveScope

func (m *Manager) RemoveScope(name string) bool

RemoveScope removes a registered scope. Returns false if the scope cannot be found.

func (*Manager) Scopes

func (m *Manager) Scopes() []*Scope

Scopes returns the registered scopes at global level.

func (*Manager) ServeDefault

func (m *Manager) ServeDefault() (*http.Server, error)

ServeDefault creates a new admin HTTP server and starts listening on the network based on the default server settings.

func (*Manager) Use

func (m *Manager) Use(handler ...interface{})

Use attaches a new middleware handler for incoming HTTP traffic.

func (*Manager) UseAdminPlugin

func (m *Manager) UseAdminPlugin(plugins ...plugin.Plugin)

UseAdminPlugin registers one or multiple plugins at manager admin level.

func (*Manager) UseFinalHandler

func (m *Manager) UseFinalHandler(fn http.Handler)

UseFinalHandler uses a new middleware handler function as final handler.

func (*Manager) UsePhase

func (m *Manager) UsePhase(phase string, handler ...interface{})

UsePhase attaches a new middleware handler to a specific phase.

func (*Manager) UsePlugin

func (m *Manager) UsePlugin(plugins ...plugin.Plugin)

UsePlugin registers one or multiple plugins at global manager level.

func (*Manager) UseScope

func (m *Manager) UseScope(scopes ...*Scope)

UseScope registers one or multiple scopes at global manager level.

type Route

type Route struct {
	Path    string
	Method  string
	Manager *Manager
	Handler RouteHandler
}

Route represents a route handler.

func (*Route) ServeHTTP

func (c *Route) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.HandlerFunc interface.

type RouteHandler

type RouteHandler func(*Context)

RouteHandler represents HTTP router handler function interface used in routes.

type Scope

type Scope struct {
	// Rules stores the scope registered rules.
	Rules *rule.Layer
	// Plugins provides the plugin register layer.
	Plugins *plugin.Layer
	// ID is used to store the plugin unique identifier.
	ID string
	// Name is used to store the scope semantic alias.
	Name string
	// Description is used to store the scope human
	// friendly description.
	Description string
}

Scope represents the HTTP configuration scope who can store rules and plugins.

func NewScope

func NewScope(name, description string) *Scope

NewScope creates a new Scope instance with the given name alias and optional description.

func (*Scope) FlushPlugins

func (s *Scope) FlushPlugins()

FlushPlugins removes all the registered plugins.

func (*Scope) FlushRules

func (s *Scope) FlushRules()

FlushRules removes all the registered rules.

func (*Scope) HandleHTTP

func (s *Scope) HandleHTTP(h http.Handler) http.Handler

HandleHTTP is used to trigger the scope layer. If all the rules passes, it will execute the scope specific registered plugins.

func (*Scope) RemovePlugin

func (s *Scope) RemovePlugin(id string) bool

RemovePlugin removes a plugin by its ID.

func (*Scope) RemoveRule

func (s *Scope) RemoveRule(id string) bool

RemoveRule removes a rule by its ID.

func (*Scope) UsePlugin

func (s *Scope) UsePlugin(plugins ...plugin.Plugin)

UsePlugin registers one or multiple plugins in the current scope.

func (*Scope) UseRule

func (s *Scope) UseRule(rules ...rule.Rule)

UseRule registers one or multiple rules in the current scope.

type ServerOptions

type ServerOptions struct {
	Port         int
	ReadTimeout  int
	WriteTimeout int
	Addr         string
	CertFile     string
	KeyFile      string
}

ServerOptions represents the supported server options.

Jump to

Keyboard shortcuts

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