faye

package module
v0.0.0-...-2b77b01 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2017 License: MIT Imports: 3 Imported by: 0

README

godoc Go Report Card CircleCI codecov

Faye

Faye client in Go.

Warning

This is a work in progress. Expect it to be broken, partially or otherwise.

About

See Faye.

Example

package main

import "fmt"
import "github.com/haggen/faye"

func main() {
    f, err := faye.New("https://example.org/faye")
    if err != nil {
      panic(err)
    }
    channel := f.Subscribe("/channel")
    for {
      m := <-channel
      fmt.Println(m.Data)
    }
}

Faye (Go) package is under The MIT License © 2017 Arthur Corenzan.

Faye protocol is under The MIT License © 2009–2017 James Coglan.

Documentation

Overview

Package faye is a client for the Faye protocol.

Faye protocol is licensed under The MIT License © 2009–2017 James Coglan. More on https://faye.jcoglan.com/.

Faye (Go) package is licensed under The MIT License © 2017 Arthur Corenzan. More on https://github.com/haggen/faye/.

Index

Constants

View Source
const (
	HandshakeAdvice = "handshake"
	Retry           = "retry"
	None            = "none"
)

Enumeration of reconnect advices.

View Source
const (
	Handshake   = "/meta/handshake"
	Connect     = "/meta/connect"
	Disconnect  = "/meta/disconnect"
	Subscribe   = "/meta/subscribe"
	Unsubscribe = "/meta/unsubscribe"
)

Enumeration of protocol channels.

View Source
const (
	Unconnected = iota
	Connecting
	Connected
	Disconnected
)

Enumeration of Client states.

View Source
const Version = "1.0"

Version of Faye protocol.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advice

type Advice struct {
	// Interval in milliseconds between connection checks.
	Interval time.Duration `json:"interval"`

	// Timeout in milliseconds for requests.
	Timeout time.Duration `json:"timeout"`

	// Advice string. May be 'none', 'handshake', or 'retry'.
	Reconnect string `json:"reconnect"`
}

Advice about what the server requires from the client.

type Client

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

Client is the end-user interface with the protocol.

func New

func New(transport Transport) *Client

New initializes and returns a new Client.

func (*Client) Connect

func (c *Client) Connect() error

Connect ...

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect ...

func (*Client) Handshake

func (c *Client) Handshake() error

Handshake ...

type Extension

type Extension interface {
	In(*Message)
	Out(*Message)
}

Extension is an interface to mutate both incoming and outgoing messages.

type Message

type Message struct {
	ID                       int         `json:"id"`
	Timestamp                int64       `json:"timestamp"`
	Ext                      interface{} `json:"ext"`
	Data                     interface{} `json:"data"`
	Advice                   *Advice     `json:"advice"`
	Version                  string      `json:"version"`
	ClientID                 string      `json:"clientId"`
	Channel                  string      `json:"channel"`
	Error                    string      `json:"error"`
	Successful               bool        `json:"successful"`
	Subscription             string      `json:"subscription"`
	SupportedConnectionTypes []string    `json:"supportedConnectionTypes"`
}

Message encode/decode both requests and responses.

type Transport

type Transport interface {
	Connect(string) error
	Disconnect() error
	Send(*Message) error
	Receive() (*Message, error)
	ConnectionType() string
	Ping()
}

Transport is the interface for communication with the server. e.g. WebSocket or Polling.

type WebSocket

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

WebSocket connects and communicates with the server via WebSocket.

func NewWebSocket

func NewWebSocket(url string) *WebSocket

NewWebSocket initializes and returns a new WebSocket transport.

func (*WebSocket) Connect

func (ws *WebSocket) Connect() error

Connect opens a connection to the WebSocket server.

func (*WebSocket) ConnectionType

func (ws *WebSocket) ConnectionType() string

ConnectionType returns "websocket". This will be used when negoticating with the server the supported connection types.

func (*WebSocket) Disconnect

func (ws *WebSocket) Disconnect() error

Disconnect closes the connection to the WebSocket server.

func (*WebSocket) Ping

func (ws *WebSocket) Ping() error

Ping write a ping message to the WebSocket server.

func (*WebSocket) Receive

func (ws *WebSocket) Receive() (*Message, error)

Receive reads a message encoded in JSON from the downstream.

func (*WebSocket) Send

func (ws *WebSocket) Send(m *Message) error

Send writes a message encoded in JSON to the upstream.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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