router

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 16 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, routes map[string]plugin.Gateway) (*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"`
}

type GatewayRoute

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

type Plugin

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

Plugin for the router maps prefixes to gateways

func WithLabel

func WithLabel(label string) Plugin

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
}

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