router

package
v3.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package router provides api service routing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(o *Options)

Option func signature

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context

func WithHandler

func WithHandler(h string) Option

WithHandler sets the handler

func WithRegister

func WithRegister(r register.Register) Option

WithRegister sets the register

func WithResolver

func WithResolver(r resolver.Resolver) Option

WithResolver sets the resolver

type Options

type Options struct {
	// Register for service lookup
	Register register.Register
	// Resolver to use
	Resolver resolver.Resolver
	// Logger micro logger
	Logger logger.Logger
	// Context is for external options
	Context context.Context
	// Handler name
	Handler string
}

Options holds the options for api router

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns options struct filled by opts

type Router

type Router interface {
	// Returns options
	Options() Options
	// Init initialize router
	Init(...Option) error
	// Stop the router
	Close() error
	// Endpoint returns an api.Service endpoint or an error if it does not exist
	Endpoint(r *http.Request) (*api.Service, error)
	// Register endpoint in router
	Register(ep *api.Endpoint) error
	// Deregister endpoint from router
	Deregister(ep *api.Endpoint) error
	// Route returns an api.Service route
	Route(r *http.Request) (*api.Service, error)
	// String representation of router
	String() string
}

Router is used to determine an endpoint for a request

var DefaultRouter Router

DefaultRouter contains default router implementation

Jump to

Keyboard shortcuts

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