router

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

router package implements a http.Handler and the ability to register routes on a gateway

Index

Constants

View Source
const (
	ScopeRead = "github.com/mutablelogic/go-server/router:read"
)

Variables

This section is empty.

Functions

func NewRoute

func NewRoute(host_prefix string, path *regexp.Regexp, fn http.HandlerFunc, methods ...string) *route

func NewWithPlugin

func NewWithPlugin(p Plugin, label string) (*router, error)

Create a new router task, and register routes from gateways

Types

type Gateway

type Gateway struct {
	Prefix      string         `json:"prefix,omitempty"`
	Label       string         `json:"label"`
	Description string         `json:"description,omitempty"`
	Routes      []GatewayRoute `json:"routes,omitempty"`
	Middleware  []string       `json:"middleware,omitempty"`
}

type GatewayRoute

type GatewayRoute struct {
	Path        string   `json:"path"`
	Description string   `json:"description,omitempty"`
	Methods     []string `json:"methods,omitempty"`
	Scopes      []string `json:"scopes,omitempty"`
	Middleware  []string `json:"middleware,omitempty"`
}

type Middleware added in v1.1.5

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

Middleware is a handler which is called before or after the request

func (Middleware) String added in v1.1.5

func (middleware Middleware) String() string

type MiddlewareFn added in v1.1.5

type MiddlewareFn func(http.HandlerFunc) http.HandlerFunc

MiddlewareFn returns a new http.HandlerFunc given a "child" http.HandlerFunc

type Plugin

type Plugin struct {
	task.Plugin
	Prefix_     types.String `json:"prefix,omitempty"`     // Path for serving the router schema, optional
	Routes      []Route      `json:"routes"`               // Routes to add to the router, optional (but useless without)
	Middleware_ []string     `json:"middleware,omitempty"` // Middleware to add to the router for all routes, optional
}

Plugin for the router maps prefixes to gateways

func WithLabel

func WithLabel(label string) Plugin

func (Plugin) Middleware added in v1.1.5

func (p Plugin) Middleware() []string

func (Plugin) Name

func (p Plugin) Name() string

func (Plugin) New

func (p Plugin) New(parent context.Context, provider iface.Provider) (iface.Task, error)

Create a new logger task with provider of other tasks

func (Plugin) Prefix

func (p Plugin) Prefix() string

func (Plugin) WithPrefix

func (p Plugin) WithPrefix(prefix string) Plugin

func (Plugin) WithRoutes

func (p Plugin) WithRoutes(r []Route) Plugin

type Route

type Route struct {
	Prefix      string     `json:"prefix"`               // Prefix path for the gateway service
	Handler     types.Task `json:"service"`              // Service handler
	Middleware_ []string   `json:"middleware,omitempty"` // Middleware to add to the router for this route, optional
}

type Router

type Router interface {
	plugin.Router
	AddHandlerEx(string, *regexp.Regexp, http.HandlerFunc, ...string) *route
}

Jump to

Keyboard shortcuts

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