router

package
v4.9.0 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: 8 Imported by: 0

Documentation

Overview

Package router provides api service routing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(e *Endpoint) map[string]string

Encode encodes an endpoint to endpoint metadata

func Validate

func Validate(e *Endpoint) error

Validate validates an endpoint to guarantee it won't blow up when being served

Types

type Endpoint

type Endpoint struct {
	// RPC Method e.g. Greeter.Hello
	Name string
	// What the endpoint is for
	Description string
	// API Handler e.g rpc, proxy
	Handler string
	// HTTP Host e.g example.com
	Host []string
	// HTTP Methods e.g GET, POST
	Method []string
	// HTTP Path e.g /greeter. Expect POSIX regex
	Path []string
	// Stream flag
	Stream bool
}

Endpoint is a mapping between an RPC method and HTTP endpoint

func Decode

func Decode(e map[string]string) *Endpoint

Decode decodes endpoint metadata into an endpoint

type Option

type Option func(o *Options)

func WithHandler

func WithHandler(h string) Option

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger sets the underline logger

func WithRegistry

func WithRegistry(r registry.Registry) Option

func WithResolver

func WithResolver(r resolver.Resolver) Option

type Options

type Options struct {
	Handler  string
	Registry registry.Registry
	Resolver resolver.Resolver
	Logger   logger.Logger
}

func NewOptions

func NewOptions(opts ...Option) Options

type Route

type Route struct {
	// Name of service
	Service string
	// The endpoint for this service
	Endpoint *Endpoint
	// Versions of this service
	Versions []*registry.Service
}

type Router

type Router interface {
	// Returns options
	Options() Options
	// Register endpoint in router
	Register(r *Route) error
	// Deregister endpoint from router
	Deregister(r *Route) error
	// Route returns an api.Service route
	Route(r *http.Request) (*Route, error)
	// Stop the router
	Stop() error
}

Router is used to determine an endpoint for a request

Directories

Path Synopsis
Package registry provides a dynamic api service router
Package registry provides a dynamic api service router

Jump to

Keyboard shortcuts

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