Documentation ¶
Overview ¶
Package router provides an interface for micro network router
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // AdvertiseTick defines how often in seconds do we scal the local registry // to advertise the local services to the network registry AdvertiseTick = 5 * time.Second // AdvertiseTTL defines network registry TTL in seconds // NOTE: this is a rather arbitrary picked value subject to change AdvertiseTTL = 120 * time.Second )
var ( // DefaultAddress is default router address DefaultAddress = ":9093" // DefaultAdvertise is default address advertised to the network DefaultAdvertise = ":9094" )
var ( // DefaultLocalMetric is default route cost for local network DefaultLocalMetric = 1 // DefaultNetworkMetric is default route cost for micro network DefaultNetworkMetric = 10 )
var ( // 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 ( // ErrWatcherStopped is returned when routing table watcher has been stopped ErrWatcherStopped = errors.New("routing table watcher stopped") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { // Type defines type of event Type EventType // Route is table rout Route Route }
Event is returned by a call to Next on the watcher.
type LookupPolicy ¶
type LookupPolicy int
LookupPolicy defines query policy
const ( // DiscardNoRoute discards query when no route is found DiscardNoRoute LookupPolicy = iota // ClosestMatch returns closest match to supplied query ClosestMatch )
func (LookupPolicy) String ¶
func (lp LookupPolicy) String() string
String returns human representation of LookupPolicy
type Option ¶
type Option func(*Options)
Option used by the router
type Options ¶
type Options struct { // ID is router id ID string // Address is router address Address string // Advertise is the address advertised to the network Advertise string // Registry is the local registry Registry registry.Registry // Networkis the network registry Network registry.Registry // Table is routing table Table Table }
Options are router options
type Query ¶
type Query interface { // Options returns query options Options() QueryOptions }
Query is routing table query
type QueryOption ¶
type QueryOption func(*QueryOptions)
QueryOption sets routing table query options
func QueryDestination ¶
func QueryDestination(a string) QueryOption
QueryDestination sets query destination address
func QueryPolicy ¶
func QueryPolicy(p LookupPolicy) QueryOption
QueryPolicy sets query policy NOTE: this might be renamed to filter or some such
type QueryOptions ¶
type QueryOptions struct { // Destination is destination address Destination string // Network is network address Network string // Router is gateway address Router Router // Metric is route metric Metric int // Policy is query lookup policy Policy LookupPolicy }
QueryOptions are routing table query options
type Route ¶
type Route struct { // Destination is destination address Destination string // Router is the network router Router Router // Network is micro network address Network string // Metric is the route cost metric Metric int // Policy defines route policy Policy RoutePolicy }
Route is network route
type RoutePolicy ¶
type RoutePolicy int
RoutePolicy defines routing table addition policy
const ( // OverrideIfExists overrides route if it already exists OverrideIfExists RoutePolicy = iota // IgnoreIfExists does not modify existing route IgnoreIfExists )
func (RoutePolicy) String ¶
func (p RoutePolicy) String() string
String returns human reprensentation of policy
type Router ¶
type Router interface { // Init initializes the router with options Init(...Option) error // Options returns the router options Options() Options // ID returns the id of the router ID() string // Table returns the routing table Table() Table // Address returns the router adddress Address() string // Network returns the network address of the router Network() string // Advertise starts advertising the routes to the network Advertise() error // Stop stops the router Stop() error // String returns debug info String() string }
Router is micro network router
type Table ¶
type Table interface { // Init initializes the router with options Init(...TableOption) error // Options returns the router options Options() TableOptions // Add adds new route to the routing table Add(Route) error // Delete deletes existing route from the routing table Delete(Route) error // Update updates route in the routing table Update(Route) error // List returns the list of all routes in the table List() ([]Route, error) // Lookup looks up routes in the routing table and returns them Lookup(Query) ([]Route, error) // Watch returns a watcher which allows to track updates to the routing table Watch(opts ...WatchOption) (Watcher, error) // Size returns the size of the routing table Size() int // String prints the routing table String() string }
Table defines routing table interface
func NewTable ¶
func NewTable(opts ...TableOption) Table
NewTable creates new routing table and returns it
type TableOptions ¶
type TableOptions struct{}
TableOptions are routing table options TODO: table options TBD in the future
type WatchOption ¶
type WatchOption func(*WatchOptions)
WatchOption is used to define what routes to watch in the table
func WatchDestination ¶
func WatchDestination(a string) WatchOption
WatchDestination sets what destination to watch Destination is usually microservice name
type WatchOptions ¶
type WatchOptions struct { // Specify destination address to watch Destination string // Specify network to watch Network string }
WatchOptions are table watcher options