Documentation ¶
Index ¶
- Variables
- func Listen(server *http.Server, opts ServerOptions) error
- func NewServer(o ServerOptions) *http.Server
- type Context
- type Instance
- func (i *Instance) GetScope(name string) *Scope
- func (i *Instance) HandleHTTP(w http.ResponseWriter, r *http.Request, next http.Handler)
- func (i *Instance) ID() string
- func (i *Instance) Metadata() *vinxi.Metadata
- func (i *Instance) NewDefaultScope(rules ...rule.Rule) *Scope
- func (i *Instance) NewScope(name, description string) *Scope
- func (i *Instance) RemoveScope(name string) bool
- func (i *Instance) Scopes() []*Scope
- func (i *Instance) UseScope(scopes ...*Scope)
- type JSONInstance
- type JSONPlugin
- type JSONRule
- type JSONScope
- type Manager
- func (m *Manager) GetInstance(name string) *Instance
- func (m *Manager) GetPlugin(name string) plugin.Plugin
- func (m *Manager) GetScope(name string) *Scope
- func (m *Manager) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler)
- func (m *Manager) Instances() []*Instance
- func (m *Manager) ListenAndServe(opts ServerOptions) (*http.Server, error)
- func (m *Manager) Manage(name, description string, proxy *vinxi.Vinxi) *Instance
- func (m *Manager) NewDefaultScope(rules ...rule.Rule) *Scope
- func (m *Manager) NewScope(name, description string) *Scope
- func (m *Manager) RemoveInstance(name string) bool
- func (m *Manager) RemovePlugin(id string) bool
- func (m *Manager) RemoveScope(name string) bool
- func (m *Manager) Scopes() []*Scope
- func (m *Manager) ServeDefault() (*http.Server, error)
- func (m *Manager) Use(handler ...interface{})
- func (m *Manager) UseAdminPlugin(plugins ...plugin.Plugin)
- func (m *Manager) UseFinalHandler(fn http.Handler)
- func (m *Manager) UsePhase(phase string, handler ...interface{})
- func (m *Manager) UsePlugin(plugins ...plugin.Plugin)
- func (m *Manager) UseScope(scopes ...*Scope)
- type Route
- type RouteHandler
- type Scope
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
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) Send ¶
Send is used to serialize and write the response as JSON with custom status code.
func (*Context) SendNoContent ¶
func (c *Context) SendNoContent()
SendNoContent replies with 204 status code.
func (*Context) SendNotFound ¶
SendNotFound replies with 404 status code and custom message.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance represents the manager instance level.
func NewInstance ¶
NewInstance creates a new vinxi manager instance.
func (*Instance) HandleHTTP ¶
HandleHTTP is triggered by the vinxi middleware layer on incoming HTTP request.
func (*Instance) Metadata ¶
func (i *Instance) Metadata() *vinxi.Metadata
Metadata returns the vinxi instance metadata struct.
func (*Instance) NewDefaultScope ¶
NewDefaultScope creates a new default scope.
func (*Instance) NewScope ¶
NewScope creates a new scope based on the given name and optional description.
func (*Instance) RemoveScope ¶
RemoveScope removes a registered scope. Returns false if the scope cannot be found.
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 New ¶
func New() *Manager
New creates a new manager able to manage and configure multiple vinxi proxy instance.
func (*Manager) GetInstance ¶
GetInstance finds and returns a vinxi managed instance.
func (*Manager) HandleHTTP ¶
HandleHTTP is triggered by the vinxi middleware layer on incoming HTTP request.
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 ¶
Manage adds a new vinxi proxy instance to be managed by the current manager instance.
func (*Manager) NewDefaultScope ¶
NewDefaultScope creates a new default scope.
func (*Manager) NewScope ¶
NewScope creates a new scope based on the given name and optional description.
func (*Manager) RemoveInstance ¶
RemoveInstance removes a registered vinxi instance. Returns false if the instance cannot be found.
func (*Manager) RemovePlugin ¶
RemovePlugin removes a plugin by its ID.
func (*Manager) RemoveScope ¶
RemoveScope removes a registered scope. Returns false if the scope cannot be found.
func (*Manager) ServeDefault ¶
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 ¶
UseAdminPlugin registers one or multiple plugins at manager admin level.
func (*Manager) UseFinalHandler ¶
UseFinalHandler uses a new middleware handler function as final handler.
type Route ¶
type Route struct { Path string Method string Manager *Manager Handler RouteHandler }
Route represents a route handler.
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 ¶
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 ¶
HandleHTTP is used to trigger the scope layer. If all the rules passes, it will execute the scope specific registered plugins.
func (*Scope) RemovePlugin ¶
RemovePlugin removes a plugin by its ID.
func (*Scope) RemoveRule ¶
RemoveRule removes a rule by its ID.