routerecorder

package
v0.0.0-...-ecdd364 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 2 Imported by: 0

README

routerecorder

Package routerecorder keeps track of each of the routes a plugin adds to the router. It is not a functioning router.

Import: github.com/ambientkit/plugin/router/routerecorder

Version: 1.0.0

Plugin Type

The plugin can be used as the following core types:

  • Logger: false
  • Storage System: false
  • Router: true
  • Template Engine: false
  • Session Manager: false

Grants

The plugin does not request any grants.

Settings

The plugin does not have any settings.

Routes

The plugin does not have any routes.

Middleware

The plugin does not have any middleware.

FuncMap

The plugin does not have a FuncMap.

Assets

The plugin does not inject any assets.

Embedded Files

The plugin does not have any embedded files.

Example Usage

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())
	}
}

Docgen by Ambient

Documentation

Overview

Package routerecorder keeps track of each of the routes a plugin adds to the router. It is not a functioning router.

Index

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) Delete

func (p *Plugin) Delete(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Delete registers a pattern with the router.

func (*Plugin) Error

func (p *Plugin) Error(status int, w http.ResponseWriter, r *http.Request)

Error shows error page based on the status code.

func (*Plugin) Get

func (p *Plugin) Get(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Get registers a pattern with the router.

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) Head

func (p *Plugin) Head(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Head registers a pattern with the router.

func (*Plugin) Options

func (p *Plugin) Options(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Options registers a pattern with the router.

func (*Plugin) Param

func (p *Plugin) Param(r *http.Request, name string) string

Param returns a URL parameter.

func (*Plugin) Patch

func (p *Plugin) Patch(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Patch registers a pattern with the router.

func (*Plugin) PluginName

func (p *Plugin) PluginName() string

PluginName returns the plugin name.

func (*Plugin) PluginVersion

func (p *Plugin) PluginVersion() string

PluginVersion returns the plugin version.

func (*Plugin) Post

func (p *Plugin) Post(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Post registers a pattern with the router.

func (*Plugin) Put

func (p *Plugin) Put(path string, fn func(http.ResponseWriter, *http.Request) (err error))

Put registers a pattern with the router.

func (*Plugin) Router

func (p *Plugin) Router(logger ambient.Logger, te ambient.Renderer) (ambient.AppRouter, error)

Router returns a router.

func (*Plugin) Routes

func (p *Plugin) Routes() []Route

Routes returns list of routes.

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

func (p *Plugin) SetNotFound(notFound http.Handler)

SetNotFound sets the NotFound function.

func (*Plugin) SetServeHTTP

func (p *Plugin) SetServeHTTP(h func(w http.ResponseWriter, r *http.Request, err error))

SetServeHTTP sets the ServeHTTP function.

func (*Plugin) StatusError

func (p *Plugin) StatusError(status int, err error) error

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.

type Route

type Route struct {
	Method string
	Path   string
}

Route represents a route.

Jump to

Keyboard shortcuts

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