sockhop

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

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

Go to latest
Published: Mar 9, 2015 License: MIT Imports: 6 Imported by: 0

README

SockHop Picture of a sock

SockHop is a super simple web socket protocol framework over Gorilla's websocket library.

License

SockHop is provided under the open source MIT license:

The MIT License (MIT)

Copyright (c) 2014 Bellerophon Mobile

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	AuthenticateJWT(sock *Sock, jwt string) error
	AuthenticateUserPass(sock *Sock, user string, pass string) error
}

type Hook

type Hook func(*Message) error

type Message

type Message struct {
	Code         string
	ID           uint64
	InResponseTo uint64
	Data         string

	Sock *Sock `json:"-"`
}

func (*Message) Reply

func (x *Message) Reply(code string, data interface{}) error

type Sock

type Sock struct {
	Socket *websocket.Conn

	Log *logberry.Task

	TextHooks map[string]Hook

	BinaryHandler func([]byte) error
	ErrorHandler  func(error) error

	Live bool
	// contains filtered or unexported fields
}

Sock is a web socket connection. It wraps a Gorilla websocket Conn and provides some basic call/response and other features.

func Dial

func Dial(url string, conf *SockConf) (*Sock, error)

func NewSock

func NewSock(conf *SockConf) (*Sock, error)

NewSock returns an unconnected Sock. Parameter conf may be nil.

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request, conf *SockConf) (*Sock, error)

Upgrade converts an HTTP connection into a web socket. An active Sock is returned, or an error if there is a problem.

func (*Sock) AddHook

func (x *Sock) AddHook(code string, hook Hook)

func (*Sock) Close

func (x *Sock) Close()

func (*Sock) Loop

func (x *Sock) Loop() error

func (*Sock) ReadMessage

func (x *Sock) ReadMessage() (*Message, error)

func (*Sock) SendBinary

func (x *Sock) SendBinary(data []byte) error

func (*Sock) SendFault

func (x *Sock) SendFault(msg string) error

func (*Sock) SendMessage

func (x *Sock) SendMessage(code string, data interface{}) error

func (*Sock) SendRequest

func (x *Sock) SendRequest(code string, data interface{}, handler chan *Message, timeout time.Duration) error

func (*Sock) SendText

func (x *Sock) SendText(data []byte) error

type SockConf

type SockConf struct {
	MaxMessageSize  int64
	ReadBufferSize  int
	WriteBufferSize int

	Authenticator Authenticator

	JWT  string
	User string
	Pass string

	BinaryHandler func(data []byte) error

	ErrorHandler func(error) error

	TLSConfig *tls.Config

	Context logberry.Context
}

SockConf encapsulates optional parameters to configure a Sock.

Jump to

Keyboard shortcuts

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