router

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 13 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 Middleware

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

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

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 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 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 *Route) context.Context

WithRoute returns a context with various route parameters

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 struct {
	// Label
	Label string `json:"label,omitempty"`

	// Matched handler
	Handler http.HandlerFunc `json:"-"`

	// Matched host
	Host string `json:"host,omitempty"`

	// Matched prefix
	Prefix string `json:"prefix,omitempty"`

	// Matched path
	Path string `json:"path,omitempty"`

	// Computed	parameters from the path
	Parameters []string `json:"parameters,omitempty"`

	// Whether the result was from the cache
	Cached bool `json:"cached,omitempty"`
}

Route is a matched route handler, with associated host, prefix and path

func (Route) String

func (r Route) String() string

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) (*Route, int)
}

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