websox

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

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

Go to latest
Published: Jun 20, 2018 License: BSD-2-Clause Imports: 16 Imported by: 0

README

websox

Sample websockets client/server for Predix

Notes on securing your instance

CheckMarx Go Security

Documentation

Overview

Package websox provides a wrapper for a client to initiate and handle data push requests from a server

Package websox provides a wrapper for a client to initiate and handle data push requests from a server

Package websox provides a wrapper for a client to initiate and handle data push requests from a server

Package websox provides a wrapper for a client to initiate and handle data push requests from a server

Index

Constants

View Source
const (
	// LogFlags are the default log flags
	LogFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
)

Variables

This section is empty.

Functions

func Client

func Client(url string, fn Actionable, pings bool, headers http.Header, logger *log.Logger) error

Client connects to url and applies the Actionable function to each message received url specifices the websocket endpoint to connect to pings will log websocket pings if set true headers supplies optional http headers for authentication logger logs actions

func MakeClientCredentialsTokenSource

func MakeClientCredentialsTokenSource(ctx context.Context, url, cid, secret string) oauth2.TokenSource

MakeClientCredentialsTokenSource returns an oauth2 token source for validation

func Oauth2Header

func Oauth2Header(ctx context.Context, url, cid, secret string) (http.Header, error)

Oauth2Header returns headers to access protected http endpoints

func Pusher

func Pusher(setup Setup, expires, pingFreq time.Duration, contacted func(), logger *log.Logger) http.HandlerFunc

Pusher gets send/recv channels from the setup function and sets up the environment for bringing up an event loop on the websocket connection

Types

type Actionable

type Actionable func(io.Reader) (interface{}, bool, error)

Actionable functions process an io.Reader and returns any relevant results a bool set false if to close the client, and an error if such is encountered

type Results

type Results struct {
	ErrMsg  string           `json:"error"`
	Payload *json.RawMessage `json:"payload"`
}

Results is used to return client results / errors on websocket pushes

type Setup

type Setup func() (chan io.Reader, chan Results)

Setup returns a channel to get data and one that return an error value and optional artifacts from the results of that action

If the setup function cannot do the required processing, it should return a nil interface channel and send an error message in the error channel

The Results channel is closed by Pusher() when it is done processing (due to session timeout or error)

func MakeFake

func MakeFake(logger *log.Logger) Setup

MakeFake returns a sample Actionable function for testing

type Stuff

type Stuff struct {
	Msg   string    `json:"msg"`
	Count int       `json:"count"`
	TS    time.Time `json:"timestamp"`
}

Stuff is a sample struct for testing

func (Stuff) NewReader

func (s Stuff) NewReader() io.Reader

NewReader is a convenience method for generating a io.Reader representing the struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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