router

package
v0.0.0-...-9451de5 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package router provides interfaces that need to be satisfied in order to implement a new router on tsuru.

Index

Constants

View Source
const HttpScheme = "http"

Variables

View Source
var (
	ErrBackendExists         = errors.New("Backend already exists")
	ErrBackendNotFound       = errors.New("Backend not found")
	ErrBackendSwapped        = errors.New("Backend is swapped cannot remove")
	ErrRouteNotFound         = errors.New("Route not found")
	ErrCNameExists           = errors.New("CName already exists")
	ErrCNameNotFound         = errors.New("CName not found")
	ErrCNameNotAllowed       = errors.New("CName as router subdomain not allowed")
	ErrCertificateNotFound   = errors.New("Certificate not found")
	ErrDefaultRouterNotFound = errors.New("No default router found")
)
View Source
var (
	BackendStatusReady    = BackendStatus("ready")
	BackendStatusNotReady = BackendStatus("not ready")
)

Functions

func BuildHealthCheck

func BuildHealthCheck(routerName string) func() error

BuildHealthCheck creates a healthcheck function for the given routerName.

It will call the HealthCheck() method in the router (only if it's also a HealthChecker), for each instance of it (including the "main" instance and all custom routers).

func Default

func Default() (string, error)

Default returns the default router

func Initialize

func Initialize() error

func InstrumentRequest

func InstrumentRequest(routerName string) func(error)

func IsSwapped

func IsSwapped(name string) (bool, string, error)

func MigrateUniqueCollection

func MigrateUniqueCollection() error

MigrateUniqueCollection only exists because old versions of tsuru (<1.2.0) allowed the insertion of incorrect duplicated entries in the db.routers collection. This migration tries its best to fix the inconsistencies in this collection and fails if that's not possible.

func Register

func Register(name string, r routerFactory)

Register registers a new router.

func Remove

func Remove(appName string) error

func Retrieve

func Retrieve(appName string) (string, error)

func Store

func Store(appName, routerName, kind string) error

Store stores the app name related with the router name.

func Swap

func Swap(r Router, backend1, backend2 string, cnameOnly bool) error

func Type

func Type(name string) (string, string, error)

func Unregister

func Unregister(name string)

func ValidCName

func ValidCName(cname, domain string) bool

validCName returns true if the cname is not a subdomain of the router current domain, false otherwise.

Types

type App

type App interface {
	GetName() string
	GetPool() string
	GetTeamOwner() string
	GetTeamsName() []string
}

App is the interface implemented by routable applications.

type AsyncRouter

type AsyncRouter interface {
	AddBackendAsync(app App) error
	SetCNameAsync(cname, name string) error
	AddRoutesAsync(name string, address []*url.URL) error
	RemoveRoutesAsync(name string, addresses []*url.URL) error
}

type BackendStatus

type BackendStatus string

type CNameMoveRouter

type CNameMoveRouter interface {
	MoveCName(cname, orgBackend, dstBackend string) error
}

type CNameRouter

type CNameRouter interface {
	SetCName(cname, name string) error
	UnsetCName(cname, name string) error
	CNames(name string) ([]*url.URL, error)
}

type CustomHealthcheckRouter

type CustomHealthcheckRouter interface {
	SetHealthcheck(name string, data router.HealthcheckData) error
}

type ErrRouterNotFound

type ErrRouterNotFound struct {
	Name string
}

func (*ErrRouterNotFound) Error

func (e *ErrRouterNotFound) Error() string

type HealthChecker

type HealthChecker interface {
	HealthCheck() error
}

type InfoRouter

type InfoRouter interface {
	GetInfo() (map[string]string, error)
}

type MessageRouter

type MessageRouter interface {
	StartupMessage() (string, error)
}

type OptsRouter

type OptsRouter interface {
	AddBackendOpts(app App, opts map[string]string) error
	UpdateBackendOpts(app App, opts map[string]string) error
}

type PlanRouter

type PlanRouter struct {
	Name    string            `json:"name"`
	Type    string            `json:"type"`
	Info    map[string]string `json:"info"`
	Default bool              `json:"default"`
}

func List

func List() ([]PlanRouter, error)

func ListWithInfo

func ListWithInfo() ([]PlanRouter, error)

type Router

type Router interface {
	GetName() string

	AddBackend(app App) error
	RemoveBackend(name string) error
	AddRoutes(name string, address []*url.URL) error
	RemoveRoutes(name string, addresses []*url.URL) error
	Addr(name string) (string, error)

	// Swap change the router between two backends.
	Swap(backend1, backend2 string, cnameOnly bool) error

	// Routes returns a list of routes of a backend.
	Routes(name string) ([]*url.URL, error)
}

Router is the basic interface of this package. It provides methods for managing backends and routes. Each backend can have multiple routes.

func Get

func Get(name string) (Router, error)

Get gets the named router from the registry.

type RouterError

type RouterError struct {
	Op  string
	Err error
}

func (*RouterError) Error

func (e *RouterError) Error() string

type StatusRouter

type StatusRouter interface {
	GetBackendStatus(name string) (status BackendStatus, detail string, err error)
}

type TLSRouter

type TLSRouter interface {
	AddCertificate(app App, cname, certificate, key string) error
	RemoveCertificate(app App, cname string) error
	GetCertificate(app App, cname string) (string, error)
}

TLSRouter is a router that supports adding and removing certificates for a given cname

Directories

Path Synopsis
api
Package hipache provides a router implementation that store routes in Redis, as specified by Hipache (https://github.com/dotcloud/hipache).
Package hipache provides a router implementation that store routes in Redis, as specified by Hipache (https://github.com/dotcloud/hipache).

Jump to

Keyboard shortcuts

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