router

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Host

func Host(ctx context.Context) string

Host returns the host from the context, or zero value if not defined

func Method added in v1.4.7

func Method(ctx context.Context) []string

Method returns the stored methods or nil if not defined

func Middleware

func Middleware(ctx context.Context) []server.Middleware

Middleware returns a set of middleware from the context, or zero value if not defined

func New added in v1.4.7

func New(c Config) (server.Task, error)

Create a new router from the configuration

func NewMatchedRoute added in v1.4.7

func NewMatchedRoute(route *route, method, host, request string, params ...string) *matchedRoute

func NewRoute added in v1.4.7

func NewRoute(ctx context.Context, host, prefix string, methods ...string) *route

func NewRouteWithPath added in v1.4.7

func NewRouteWithPath(ctx context.Context, host, prefix, path string, methods ...string) *route

func NewRouteWithRegexp added in v1.4.7

func NewRouteWithRegexp(ctx context.Context, host, prefix string, path *regexp.Regexp, methods ...string) *route

func Params

func Params(ctx context.Context) []string

Params returns the path parameters from the context, or zero value if not defined

func Prefix

func Prefix(ctx context.Context) string

Prefix returns the prefix from the context, or zero value if not defined

func Scope added in v1.4.7

func Scope(ctx context.Context) []string

Scope returns the stored scope or nil if not defined

func Time

func Time(ctx context.Context) time.Time

Time returns the stored time value or the zero value if not defined

func WithHost

func WithHost(ctx context.Context, host string) context.Context

WithHost returns a context with the given host

func WithHostPrefix

func WithHostPrefix(ctx context.Context, host, prefix string) context.Context

WithHostPrefix returns a context with the given host and prefix

func WithMethod added in v1.4.7

func WithMethod(ctx context.Context, method ...string) context.Context

WithMethod returns a context with the given methods

func WithMiddleware

func WithMiddleware(ctx context.Context, middleware ...server.Middleware) context.Context

WithMiddleware returns a context with the given middleware

func WithPrefix

func WithPrefix(ctx context.Context, prefix string) context.Context

WithPrefix returns a context with the given prefix

func WithRoute

func WithRoute(ctx context.Context, route *matchedRoute) context.Context

WithRoute returns a context with various route parameters

func WithScope added in v1.4.7

func WithScope(ctx context.Context, scope ...string) context.Context

WithScope returns a context with the given scooes

func WithTime

func WithTime(ctx context.Context, t time.Time) context.Context

WithTime returns a context with the given time

Types

type Config

type Config struct {
	Services ServiceConfig `hcl:"services"`
}

func (Config) Description

func (Config) Description() string

Description returns the description of the service

func (Config) Name

func (Config) Name() string

Name returns the name of the service

func (Config) New

func (c Config) New() (server.Task, error)

Create a new router from the configuration

type Route

type Route interface {
	server.Route

	// Set scope
	SetScope(...string) Route
}

type Router

type Router interface {
	server.Router

	// Match a host, method and path to a handler. Returns the appropriate
	// http status code, which will be 200 on success, 404 or 405 and
	// path parameters extracted from the path.
	Match(host, method, path string) (*matchedRoute, int)

	// Add a service endpoint to the router, with specified host/prefix combinarion.
	AddServiceEndpoints(string, server.ServiceEndpoints, ...server.Middleware)

	// Return all known scopes
	Scopes() []string
}

type RouterContextKey

type RouterContextKey int

type ServiceConfig

type ServiceConfig map[string]struct {
	Service    server.ServiceEndpoints `hcl:"service"`
	Middleware []server.Middleware     `hcl:"middleware"`
}

Jump to

Keyboard shortcuts

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