router

package
v0.0.0-...-0bb4d62 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteTypePrefix = "prefix"
	RouteTypeExact  = "exact"
)
View Source
const (
	SegmentsModePreserve = "preserve"
	SegmentsModeIgnore   = "ignore"
)

Variables

View Source
var EnableDebugOutput bool

Functions

func NewAPIHandler

func NewAPIHandler(rout *Router) (api http.Handler, err error)

func RegisterMetrics

func RegisterMetrics(r prometheus.Registerer)

RegisterMetrics registers Prometheus metrics from the router module and the modules that it directly depends on. To use the default (global) registry, pass prometheus.DefaultRegisterer.

func VersionInfo

func VersionInfo() (v string)

VersionInfo returns human-readable version information in a format suitable for concatenation with other messages.

Types

type Backend

type Backend struct {
	BackendID     string `bson:"backend_id"`
	BackendURL    string `bson:"backend_url"`
	SubdomainName string `bson:"subdomain_name"`
}

func (*Backend) ParseURL

func (be *Backend) ParseURL() (*url.URL, error)

type MongoReplicaSet

type MongoReplicaSet struct {
	Members []MongoReplicaSetMember `bson:"members"`
}

type MongoReplicaSetMember

type MongoReplicaSetMember struct {
	Name    string              `bson:"name"`
	Optime  bson.MongoTimestamp `bson:"optime"`
	Current bool                `bson:"self"`
}

type Options

type Options struct {
	MongoURL             string
	MongoDBName          string
	MongoPollInterval    time.Duration
	BackendConnTimeout   time.Duration
	BackendHeaderTimeout time.Duration
	LogFileName          string
}

type Route

type Route struct {
	IncomingPath string `bson:"incoming_path"`
	RouteType    string `bson:"route_type"`
	Handler      string `bson:"handler"`
	BackendID    string `bson:"backend_id"`
	RedirectTo   string `bson:"redirect_to"`
	RedirectType string `bson:"redirect_type"`
	SegmentsMode string `bson:"segments_mode"`
	Disabled     bool   `bson:"disabled"`
}

type Router

type Router struct {
	ReloadChan chan bool
	// contains filtered or unexported fields
}

Router is a wrapper around an HTTP multiplexer (trie.Mux) which retrieves its routes from a passed mongo database.

TODO: decouple Router from its database backend. Router should not know anything about the database backend. Its representation of the route table should be independent of the underlying DBMS. Route should define an abstract interface for some other module to be able to bulk-load and incrementally update routes. Since Router should not care where its routes come from, Route and Backend should not contain bson fields. MongoReplicaSet, MongoReplicaSetMember etc. should move out of this module.

func NewRouter

func NewRouter(o Options) (rt *Router, err error)

NewRouter returns a new empty router instance. You will need to call SelfUpdateRoutes() to initialise the self-update process for routes.

func (*Router) SelfUpdateRoutes

func (rt *Router) SelfUpdateRoutes()

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP delegates responsibility for serving requests to the proxy mux instance for this router.

Jump to

Keyboard shortcuts

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