stubborn

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 14 Imported by: 3

README

Stubborn

Stubborn is a framework that's written in Go for clients that uses duplex protocols such as WebSocket.

Examples
Status

The Stubborn framework provides a complete and tested persistent connection for the duplex protocols using various types of clients.

Installation
go get github.com/filinvadim/stubborn
Stubborn advantages
  1. Agnostic to any clients by DuplexConnector interface.
  2. Therefore, it's fully testable using mock that implements three methods:
    Close() error
    ReadMessage() (messageType int, p []byte, err error)
    WriteMessage(messageType int, data []byte) error
    
  3. Persistence. Stubborn framework won't stop fetching data even if panic() occurs (that's useful if for example Gorilla WebSocket was used as client).
  4. Fairly configurable for any API requirements.
  5. No external dependencies whatsoever.
Stubborn disadvantages
  1. Framework wasn't benchmark tested but expected average speed.

Documentation

Overview

Author of this file is https://github.com/nsf https://github.com/nsf/jsondiff/blob/master/LICENSE

Index

Constants

View Source
const (
	TextMessage   = 1
	BinaryMessage = 2
	PingMessage   = 9
	PongMessage   = 10
)

Variables

View Source
var (
	ErrCritical = errors.New("critical")
	ErrMajor    = errors.New("major")
	ErrMinor    = errors.New("minor")
)

Functions

func GZipCompress

func GZipCompress(input string) ([]byte, error)

func GZipDecompress

func GZipDecompress(input []byte) ([]byte, error)

func NewStubborn

func NewStubborn(
	conf Config,
) *client

Types

type AuthHandler

type AuthHandler func() (req []byte, resp []byte, err error)

type Config

type Config struct {
	URL             string
	IsReconnectable bool
	// default message type
	MessageType int
	// use your favourite logger
	Print PrintFunc
	// use your favourite client
	Dialerf     DialerFunc
	AuthTimeOut time.Duration
	// it is easier to define expected error because exceptions always unexpected :)
	UnimportantErrs []error
}

type DialerFunc

type DialerFunc func() (DuplexConnector, error)

type Difference

type Difference int
const (
	FullMatch Difference = iota
	SupersetMatch
	NoMatch
	FirstArgIsInvalidJson
	SecondArgIsInvalidJson
	BothArgsAreInvalidJson
)

func CompareJSON

func CompareJSON(a, b []byte, opts *Options) (Difference, string)

Compares two JSON documents using given options. Returns difference type and a string describing differences.

FullMatch means provided arguments are deeply equal.

SupersetMatch means first argument is a superset of a second argument. In this diffContext being a superset means that for each object or array in the hierarchy which don't match exactly, it must be a superset of another one. For example:

{"a": 123, "b": 456, "c": [7, 8, 9]}

Is a superset of:

{"a": 123, "c": [7, 8]}

NoMatch means there is no match.

The rest of the difference types mean that one of or both JSON documents are invalid JSON.

Returned string uses a format similar to pretty printed JSON to show the human-readable difference between provided JSON documents. It is important to understand that returned format is not a valid JSON and is not meant to be machine readable.

func (Difference) String

func (d Difference) String() string

type DuplexConnector added in v0.3.0

type DuplexConnector interface {
	Close() error
	ReadMessage() (messageType int, p []byte, err error)
	WriteMessage(messageType int, data []byte) error
}

type ErrorHandler

type ErrorHandler func(err error)

type KeepAlive

type KeepAlive struct {
	Tick       <-chan time.Time
	CustomPing func() (msgType int, payload []byte)
	CustomPong func(msgTp int, data []byte) (msgType int, payload []byte)
}

type MessageHandler

type MessageHandler func(resp []byte)

type Options

type Options struct {
	Normal           Tag
	Added            Tag
	Removed          Tag
	Changed          Tag
	Prefix           string
	Indent           string
	PrintTypes       bool
	ChangedSeparator string
}

func DefaultConsoleOptions

func DefaultConsoleOptions() Options

Provides a set of options that are well suited for console output. Options use ANSI foreground color escape sequences to highlight changes.

func DefaultHTMLOptions

func DefaultHTMLOptions() Options

Provides a set of options that are well suited for HTML output. Works best inside <pre> tag.

func DefaultJSONOptions

func DefaultJSONOptions() Options

Provides a set of options in JSON format that are fully parseable.

type PrintFunc

type PrintFunc func(args ...interface{})

type Tag

type Tag struct {
	Begin string
	End   string
}

Directories

Path Synopsis
example
http2 module
wss module

Jump to

Keyboard shortcuts

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