client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2016 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Balancing schemes
	RoundRobin = "RR"
	LeastConn  = "LC"

	// Default timeout in milliseconds for clients and server connections
	DefaultTimeout = 2000

	// Default interval in milliseconds between health checks
	DefaultCheckInterval = 5000

	// Default network connections are TCP
	DefaultNet = "tcp"

	// All RoundRobin backends are weighted, with a default of 1
	DefaultWeight = 1

	// RoundRobin is the default balancing scheme
	DefaultBalance = RoundRobin

	// Default for Fall and Rise is 2
	DefaultFall = 2
	DefaultRise = 2
)

Variables

View Source
var (
	// Status400s is a set of response codes to set an Error page for all 4xx responses.
	Status400s = []int{400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418}
	// Status500s is a set of response codes to set an Error page for all 5xx responses.
	Status500s = []int{500, 501, 502, 503, 504, 505}
)

Functions

This section is empty.

Types

type BackendConfig

type BackendConfig struct {
	// Name must be unique for this service.
	// Used for reference and for the HTTP API.
	Name string `json:"name"`

	// Addr must in the form ip:port
	Addr string `json:"address"`

	// Network must be "tcp" or "udp".
	// Default is "tcp"
	Network string `json:"network,omitempty"`

	// CheckAddr must be in the form ip:port.
	// A TCP connect is performed against this address to determine server
	// availability. If this is empty, no checks will be performed.
	CheckAddr string `json:"check_address"`

	// Weight is always used for RoundRobin balancing. Default is 1
	Weight int `json:"weight"`
}

BackendConfig defines the parameters unique for individual backends.

func (BackendConfig) Equal

func (b BackendConfig) Equal(other BackendConfig) bool

func (*BackendConfig) Marshal

func (b *BackendConfig) Marshal() []byte

func (BackendConfig) SetDefaults

func (b BackendConfig) SetDefaults() BackendConfig

return a copy of the BackendConfig with default values set

func (*BackendConfig) String

func (b *BackendConfig) String() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an http client for communicating with the shuttle server api

func NewClient

func NewClient(addr string) *Client

An http client for communicating with the shuttle server.

func (*Client) GetConfig

func (c *Client) GetConfig() (*Config, error)

GetConfig retrieves the configuration for a running shuttle server.

func (*Client) RemoveBackend

func (c *Client) RemoveBackend(service, backend string) error

RemoveBackend removes a backend from its service on a running shuttle server.

func (*Client) RemoveService

func (c *Client) RemoveService(service string) error

RemoveService removes a service and its backends from a running shuttle server.

func (*Client) UpdateBackend

func (c *Client) UpdateBackend(service string, backend *BackendConfig) error

UpdateBackend adds or updates a single backend on a running shuttle server.

func (*Client) UpdateConfig

func (c *Client) UpdateConfig(config *Config) error

UpdateConfig updates the running config on a shuttle server. This will update globals settings and add services, but currently doesn't remove any running service or backends.

func (*Client) UpdateService

func (c *Client) UpdateService(service *ServiceConfig) error

UpdateService adds or updates a service on a running shuttle server.

type Config

type Config struct {
	// Balance method
	// Valid values are "RR" for RoundRobin, the default, and "LC" for
	// LeastConnected.
	Balance string `json:"balance,omitempty"`

	// CheckInterval is in time in milliseconds between service health checks.
	CheckInterval int `json:"check_interval"`

	// Fall is the number of failed health checks before a service is marked
	// down.
	Fall int `json:"fall"`

	// Rise is the number of successful health checks before a down service is
	// marked up.
	Rise int `json:"rise"`

	// ClientTimeout is the maximum inactivity time, in milliseconds, for a
	// connection to the client before it is closed.
	ClientTimeout int `json:"client_timeout"`

	// ServerTimeout is the maximum inactivity time, in milliseconds, for a
	// connection to the backend before it is closed.
	ServerTimeout int `json:"server_timeout"`

	// DialTimeout is the timeout in milliseconds for connections to the
	// backend service, including name resolution.
	DialTimeout int `json:"connect_timeout"`

	// HTTPSRedirect when set to true, redirects non-https request to https on
	// all services. The request may either have Scheme set to 'https',  or
	// have an "X-Forwarded-Proto: https" header.
	HTTPSRedirect bool `json:"https-redirect"`

	// Services is a slice of ServiceConfig for each service. A service
	// corresponds to one listening connection, and a number of backends to
	// proxy.
	Services []ServiceConfig `json:"services"`
}

Config is the global configuration for all Services. Defaults set here can be overridden by individual services.

func (*Config) Marshal

func (c *Config) Marshal() []byte

Marshal returns an entire config as a json []byte.

func (*Config) String

func (c *Config) String() string

The string representation of a config is in json.

type ServiceConfig

type ServiceConfig struct {
	// Name is the unique name of the service. This is used only for reference
	// and in the HTTP API.
	Name string `json:"name"`

	// Addr is the listening address for this service. Must be in the form
	// "ip:addr"
	Addr string `json:"address"`

	// Network must be "tcp" or "udp".
	// Default is "tcp"
	Network string `json:"network,omitempty"`

	// Balance method
	// Valid values are "RR" for RoundRobin, the default, and "LC" for
	// LeastConnected.
	Balance string `json:"balance,omitempty"`

	// CheckInterval is in time in milliseconds between service health checks.
	CheckInterval int `json:"check_interval"`

	// Fall is the number of failed health checks before a service is marked.
	Fall int `json:"fall"`

	// Rise is the number of successful health checks before a down service is
	// marked up.
	Rise int `json:"rise"`

	// ClientTimeout is the maximum inactivity time, in milliseconds, for a
	// connection to the client before it is closed.
	ClientTimeout int `json:"client_timeout"`

	// ServerTimeout is the maximum inactivity time, in milliseconds, for a
	// connection to the backend before it is closed.
	ServerTimeout int `json:"server_timeout"`

	// DialTimeout is the timeout in milliseconds for connections to the
	// backend service, including name resolution.
	DialTimeout int `json:"connect_timeout"`

	// HTTPSRedirect when set to true, redirects non-https request to https. The
	// request may either have Scheme set to 'https',  or have an
	// "X-Forwarded-Proto: https" header.
	HTTPSRedirect bool `json:"https-redirect"`

	// Virtualhosts is a set of virtual hostnames for which this service should
	// handle HTTP requests.
	VirtualHosts []string `json:"virtual_hosts,omitempty"`

	// ErrorPages are responses to be returned for HTTP error codes. Each page
	// is defined by a URL mapped and is mapped to a list of error codes that
	// should return the content at the URL. Error pages are retrieved ahead of
	// time if possible, and cached.
	ErrorPages map[string][]int `json:"error_pages,omitempty"`

	// Backends is a list of all servers handling connections for this service.
	Backends []BackendConfig `json:"backends,omitempty"`

	// Maintenance mode is a flag to return 503 status codes to clients
	// without visiting backends.
	MaintenanceMode bool `json:"maintenance_mode"`
}

Subset of service fields needed for configuration.

func (ServiceConfig) DeepEqual

func (s ServiceConfig) DeepEqual(other ServiceConfig) bool

Check for equality including backends

func (ServiceConfig) Equal

func (s ServiceConfig) Equal(other ServiceConfig) bool

Compare a service's settings, ignoring individual backends.

func (*ServiceConfig) Marshal

func (b *ServiceConfig) Marshal() []byte

func (ServiceConfig) Merge

Create a new config by merging the values from the current config with those set in the new config

func (ServiceConfig) SetDefaults

func (s ServiceConfig) SetDefaults() ServiceConfig

Return a copy of ServiceConfig with any unset fields to their default values

func (*ServiceConfig) String

func (b *ServiceConfig) String() string

Jump to

Keyboard shortcuts

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