Documentation ¶
Overview ¶
Package switchboard composes an HTTP API out of a collection of HTTP service backends.
Backend services register themselves with frontend exchanges by pushing their configuration into etcd. This configuration describes HTTP methods and URL patterns that the service is capable of responding to. Exchanges respond to API consumers and route their requests to service backends. They watch for configuration changes in etcd and update their routing rules to add and remove routes as services come and go.
Index ¶
- type Exchange
- type ExchangeServeMux
- func (mux *ExchangeServeMux) Add(method, pattern, address string)
- func (mux *ExchangeServeMux) Match(method, pattern string) (*[]string, error)
- func (mux *ExchangeServeMux) Remove(method, pattern, address string)
- func (mux *ExchangeServeMux) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- type Routes
- type Service
- func (service *Service) Address() string
- func (service *Service) Broadcast(interval uint64, ttl uint64, stop chan bool)
- func (service *Service) ID() string
- func (service *Service) Register(ttl uint64) (*ServiceRecord, error)
- func (service *Service) Routes() Routes
- func (service *Service) Unregister() error
- type ServiceRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exchange ¶
type Exchange struct {
// contains filtered or unexported fields
}
Exchange watches for service changes in etcd and update an ExchangeServeMux.
func NewExchange ¶
func NewExchange(namespace string, client *etcd.Client, mux *ExchangeServeMux) *Exchange
NewExchange creates a new exchange configured to watch for changes in a given etcd directory.
func (*Exchange) Register ¶
func (exchange *Exchange) Register(service *ServiceRecord)
Register adds routes exposed by a service to the ExchangeServeMux.
func (*Exchange) Unregister ¶
func (exchange *Exchange) Unregister(service *ServiceRecord)
Unregister removes routes exposed by a service from the ExchangeServeMux.
type ExchangeServeMux ¶
type ExchangeServeMux struct {
// contains filtered or unexported fields
}
ExchangeServeMux is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns to find the service that can respond to it and proxies the request to the appropriate backend. Pattern matching logic is based on pat.go.
func NewExchangeServeMux ¶
func NewExchangeServeMux() *ExchangeServeMux
NewExchangeServeMux allocates and returns a new ExchangeServeMux.
func (*ExchangeServeMux) Add ¶
func (mux *ExchangeServeMux) Add(method, pattern, address string)
Add registers the address of a backend service as a handler for an HTTP method and URL pattern.
func (*ExchangeServeMux) Match ¶
func (mux *ExchangeServeMux) Match(method, pattern string) (*[]string, error)
Match finds backend service addresses capable of handling a request for the given HTTP method and URL pattern. An error is returned if no addresses are registered for the given HTTP method and URL pattern.
func (*ExchangeServeMux) Remove ¶
func (mux *ExchangeServeMux) Remove(method, pattern, address string)
Remove unregisters the address of a backend service as a handler for an HTTP method and URL pattern.
func (*ExchangeServeMux) ServeHTTP ¶
func (mux *ExchangeServeMux) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP dispatches the request to the backend service whose pattern most closely matches the request URL.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service responds to HTTP requests for a set of endpoints described by a JSON schema.
func NewService ¶
NewService creates a service that can be registered with etcd to handle requests from an exchange.
func (*Service) Broadcast ¶
Broadcast registers this service with etcd every interval seconds. The ttl is the time to live for the service record, in seconds. This blocking call will terminate when a value is received on the stop channel.
func (*Service) Register ¶
func (service *Service) Register(ttl uint64) (*ServiceRecord, error)
Register adds a service record to etcd. The ttl is the time to live for the service record, in seconds. A ttl of 0 registers a service record that never expires.
func (*Service) Routes ¶
Routes returns the map of HTTP methods to URL patterns configured for this service.
func (*Service) Unregister ¶
Unregister destroys the service record in etcd. An error is returned if the service isn't registered.
type ServiceRecord ¶
type ServiceRecord struct { ID string `json:"id"` Address string `json:"address"` Routes Routes `json:"routes"` }
ServiceRecord is a representation of a service stored in etcd and used by exchanges.