Documentation ¶
Overview ¶
Package routerecorder keeps track of each of the routes a plugin adds to the router. It is not a functioning router.
Index ¶
- type Plugin
- func (p *Plugin) Delete(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Error(status int, w http.ResponseWriter, r *http.Request)
- func (p *Plugin) Get(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Handle(method string, path string, ...)
- func (p *Plugin) Head(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Options(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Param(r *http.Request, name string) string
- func (p *Plugin) Patch(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) PluginName() string
- func (p *Plugin) PluginVersion() string
- func (p *Plugin) Post(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Put(path string, fn func(http.ResponseWriter, *http.Request) (err error))
- func (p *Plugin) Router(logger ambient.Logger, te ambient.Renderer) (ambient.AppRouter, error)
- func (p *Plugin) Routes() []Route
- func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) SetNotFound(notFound http.Handler)
- func (p *Plugin) SetServeHTTP(h func(w http.ResponseWriter, r *http.Request, err error))
- func (p *Plugin) StatusError(status int, err error) error
- func (p *Plugin) Wrap(handler http.HandlerFunc) func(w http.ResponseWriter, r *http.Request) (err error)
- type Route
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin represents an Ambient plugin.
func New ¶
func New() *Plugin
New returns an Ambient plugin for a router that records routes.
Example ¶
package main import ( "log" "github.com/ambientkit/ambient" "github.com/ambientkit/ambient/pkg/ambientapp" "github.com/ambientkit/plugin/logger/zaplogger" "github.com/ambientkit/plugin/router/routerecorder" "github.com/ambientkit/plugin/storage/memorystorage" ) func main() { plugins := &ambient.PluginLoader{ // Core plugins are implicitly trusted. Router: routerecorder.New(), TemplateEngine: nil, SessionManager: nil, // Trusted plugins are those that are typically needed to boot so they // will be enabled and given full access. TrustedPlugins: map[string]bool{}, Plugins: []ambient.Plugin{}, Middleware: []ambient.MiddlewarePlugin{ // Middleware - executes top to bottom. }, } _, _, err := ambientapp.NewApp("myapp", "1.0", zaplogger.New(), ambient.StoragePluginGroup{ Storage: memorystorage.New(), }, plugins) if err != nil { log.Fatalln(err.Error()) } }
Output:
func (*Plugin) Handle ¶
func (p *Plugin) Handle(method string, path string, fn func(http.ResponseWriter, *http.Request) (err error))
Handle registers a pattern with the router.
func (*Plugin) PluginName ¶
PluginName returns the plugin name.
func (*Plugin) PluginVersion ¶
PluginVersion returns the plugin version.
func (*Plugin) ServeHTTP ¶
func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes the incoming http.Request based on method and path extracting path parameters as it goes.
func (*Plugin) SetNotFound ¶
SetNotFound sets the NotFound function.
func (*Plugin) SetServeHTTP ¶
SetServeHTTP sets the ServeHTTP function.
func (*Plugin) StatusError ¶
StatusError returns an error with the status code.
func (*Plugin) Wrap ¶
func (p *Plugin) Wrap(handler http.HandlerFunc) func(w http.ResponseWriter, r *http.Request) (err error)
Wrap a standard http handler so it can be used easily.