proxy

package
v0.0.0-...-d3bb58b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

A Connection represents a single websocket.

Each connection has three main goroutines:

The writer reads messages from the 'messageSend' channel and writes them out to the socket. It will stop when the 'quit' channel is closed. A separate writer is required because we have to ensure that only one goroutine calls the send methods concurrently.

The reader reads messages from the socket, and processes them, writing responses into the messageSend channel. It also has responsibility for cleaning up: when it stops, it closes the socket and the 'quit' channel (thus stopping writer and syncPump). The reader is stopped on errors from the websocket, which can be due to the socket being closed, a close response being received, or a ping timeout.

The syncPump calls /sync on the upstream server, and writes responses into the messageSend channel. It is stopped by the 'quit' channel being closed. On error, it tells the writer to send a close request, to initiate the shutdown process.

func New

func New(syncer *Syncer, ws *websocket.Conn) *Connection

New creates a new Connection for an incoming websocket upgrade request

func (*Connection) SendClose

func (c *Connection) SendClose(closeCode int, text string)

func (*Connection) SendMessage

func (c *Connection) SendMessage(body []byte)

func (*Connection) Start

func (c *Connection) Start()

type SyncError

type SyncError struct {
	StatusCode  int
	ContentType string
	Body        []byte
}

an error returned when the /sync endpoint returns a non-200.

func (*SyncError) Error

func (s *SyncError) Error() string

type Syncer

type Syncer struct {
	UpstreamURL string

	SyncParams url.Values
	// contains filtered or unexported fields
}

func (*Syncer) MakeRequest

func (s *Syncer) MakeRequest() ([]byte, error)

MakeRequest sends the sync request, and returns the body of the response, or an error.

It keeps track of the 'next_batch' from the result, and uses it to se the 'since' parameter for the next call.

Note that this method is not thread-safe; there should be only one concurrent call per Syncer.

If /sync returns a non-200 response, the error returned will be a SyncError.

Jump to

Keyboard shortcuts

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