Documentation ¶
Overview ¶
Package router provides a network routing control plane
Index ¶
- Variables
- type Event
- type EventType
- type LookupOption
- type LookupOptions
- type Next
- type Option
- type Options
- type Random
- type ReadOption
- type ReadOptions
- type RoundRobin
- type Route
- type Router
- type SelectOption
- type Selector
- type SelectorOptions
- type StatusCode
- type Table
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLink is default network link DefaultLink = "local" // DefaultLocalMetric is default route cost for a local route DefaultMetric int64 = 1 // DefaultNetwork is default micro network DefaultNetwork = "nitro" // ErrRouteNotFound is returned when no route was found in the routing table ErrRouteNotFound = errors.New("route not found") // ErrDuplicateRoute is returned when the route already exists ErrDuplicateRoute = errors.New("duplicate route") )
var ( // ErrNoneAvailable is returned by select when no routes were provided to select from ErrNoneAvailable = errors.New("none available") )
var ( // ErrWatcherStopped is returned when routing table watcher has been stopped ErrWatcherStopped = errors.New("watcher stopped") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { // Unique id of the event Id string // Type defines type of event Type EventType // Timestamp is event timestamp Timestamp time.Time // Route is table route Route Route }
Event is returned by a call to Next on the watcher.
type LookupOption ¶
type LookupOption func(*LookupOptions)
LookupOption sets routing table query options
func LookupGateway ¶
func LookupGateway(g string) LookupOption
LookupGateway sets gateway address to query
func LookupNetwork ¶
func LookupNetwork(n string) LookupOption
LookupNetwork sets network name to query
type LookupOptions ¶
type LookupOptions struct { // Address of the service Address string // Gateway is route gateway Gateway string // Network is network address Network string // Router is router id Router string // Link to query Link string }
LookupOptions are routing table query options TODO replace with Filter(Route) bool
func NewLookup ¶
func NewLookup(opts ...LookupOption) LookupOptions
NewLookup creates new query and returns it
type Options ¶
type Options struct { // Id is router id Id string // Address is router address Address string // Gateway is network gateway // 连接局域网其他主机上的db registry的时候会用到 Gateway string // Network is network address // 作为net.LookupSRV(service, proto, name string)函数的name参数 Network string // Registry is the local registry Registry registry.Table // Context for additional options Context context.Context // Cache routes Cache bool }
Options are router options
type ReadOption ¶
type ReadOption func(o *ReadOptions)
type ReadOptions ¶
type ReadOptions struct {
App string
}
type RoundRobin ¶
type RoundRobin struct{}
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(routes []string, opts ...SelectOption) (Next, error)
type Route ¶
type Route struct { // App is destination service name App string // Address is service node address Address string // Gateway is route gateway Gateway string // Network is network address Network string // Router is router id Router string // Link is network link Link string // Metric is the route cost metric Metric int64 // Metadata for the route Metadata map[string]string }
Route is a network route
func Filter ¶
func Filter(routes []Route, opts LookupOptions) []Route
filterRoutes finds all the routes for given network and router and returns them
type Router ¶
type Router interface { // Init initializes the router with options Init(...Option) error // Options returns the router options Options() Options // The routing table Table() Table // Lookup queries routes in the routing table Lookup(service string, opts ...LookupOption) ([]Route, error) // Watch returns a watcher which tracks updates to the routing table Watch(opts ...WatchOption) (Watcher, error) // Close the router Close() error // Returns the router implementation String() string }
Router is an interface for a routing control plane
type SelectOption ¶
type SelectOption func(o *SelectorOptions)
type Selector ¶
type Selector interface { // Select a route from the pool using the strategy Select([]string, ...SelectOption) (Next, error) }
Selector selects a route from a pool
type SelectorOptions ¶
type SelectorOptions struct{}
type StatusCode ¶
type StatusCode int
StatusCode defines router status
const ( // Running means the router is up and running Running StatusCode = iota // Stopped means the router has been stopped Stopped // Error means the router has encountered error Error )
type Table ¶
type Table interface { // Create new route in the routing table Create(Route) error // Delete existing route from the routing table Delete(Route) error // Update route in the routing table Update(Route) error // Read is for querying the table Read(...ReadOption) ([]Route, error) }
Table is an interface for routing table
type WatchOption ¶
type WatchOption func(*WatchOptions)
WatchOption is used to define what routes to watch in the table
func WatchApp ¶
func WatchApp(s string) WatchOption
WatchApp sets what service routes to watch App is the microservice name
type WatchOptions ¶
type WatchOptions struct { // App allows to watch specific service routes App string }
WatchOptions are table watcher options TODO: expand the options to watch based on other criteria