wsu

package module
v0.0.0-...-cb6fc70 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: Apache-2.0 Imports: 5 Imported by: 2

README

wsu Godoc

Websockets Utilities

Client connection

Sample to get the latest 10000 Bitcoin-USD exchange events from GDAX/Coinbase

package main

import (
        "log"

        "github.com/orijtech/wsu"
)

func main() {
        conn, err := wsu.NewClientConnection(&wsu.ClientSetup{
                URL: "wss://ws-feed.gdax.com",
        })
        if err != nil {
                log.Fatal(err)
        }
        defer conn.Close()

        conn.Send(&wsu.Message{
                Frame: []byte(`{"type": "subscribe", "product_ids": ["BTC-USD"]}`),
        })

        for i := 0; i < 10000; i++ {
                msg, ok := conn.Receive()
                if !ok {
                        break
                }
                log.Printf("#%d: TimeAt: (%v) Sequence #%d Frame: %s", i, msg.TimeAt, msg.Sequence, msg.Frame)
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientSetup

type ClientSetup struct {
	URL       string `json:"url,omitempty"`
	OriginURL string `json:"origin,omitempty"`
}

type Connection

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

func ConnectionFromWebsocket

func ConnectionFromWebsocket(conn *websocket.Conn) (*Connection, error)

func NewClientConnection

func NewClientConnection(cs *ClientSetup) (*Connection, error)

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Receive

func (c *Connection) Receive() (msg *Message, ok bool)

func (*Connection) Send

func (c *Connection) Send(msg *Message)

type Message

type Message struct {
	N        int    `json:"n,omitempty"`
	Err      error  `json:"error,omitepty"`
	Frame    []byte `json:"frame,omitempty"`
	Sequence uint64 `json:"seq,omitempty"`

	// WriteAck is an optional function that you can set when
	// providing a message to the Write routine, to have the write
	// byte count and error returned, after the respective write.
	WriteAck func(int, error) error

	// TimeAt is an output only field that's set
	// only when receiving to indicate the time that
	// a message was received.
	TimeAt time.Time `json:"time_at,omitempty"`
}

Jump to

Keyboard shortcuts

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