gusk

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

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 6 Imported by: 0

README

gusk-server-go

Is a Golang library for realtime web applications. It enables realtime, bi-directional communication between web clients and servers. It has two parts: a client-side library that runs in the browser, and a server-side library for Golang.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ModeClient Modes cfg: for server send to client
	ModeClient = struct {
		Log              string
		SetConfiguration string
		CloseGusk        string
	}{
		Log:              "server->client:log",
		SetConfiguration: "server->client:set-configuration",
		CloseGusk:        "server->client:close-gusk",
	}
	// ModeServer Modes cfg: for client send to server
	ModeServer = struct {
		CloseGusk                   string
		GetConfiguration            string
		SetConfigurationReconection string
	}{
		CloseGusk:                   "client->server:close-gusk",
		GetConfiguration:            "client->server:get-configuration",
		SetConfigurationReconection: "client->server:set-configuration-reconection",
	}
)

Functions

func NewSocket

func NewSocket(handler func(*Socket), upgraderConfig ...*Upgrader) func(http.ResponseWriter, *http.Request)

NewSocket create new handler socket

Types

type H

type H map[string]interface{}

H is a shortcut for map[string]interface{}

type Message

type Message struct {
	Event string
	Data  interface{}
}

Message model

type Socket

type Socket struct {
	WS *websocket.Conn `json:"-"`
	// ID user conection
	ID   string
	HTTP struct {
		Request *http.Request
	} `json:"-"`
	// Is Socket
	Upgrader    *Upgrader   `json:"-"`
	Connect     bool        `json:"-"`
	Finish      chan error  `json:"-"`
	SocketData  *socketData `json:"-"`
	Reconection bool        `json:"-"`
	OnClose     func()      `json:"-"`
}

Socket model for conection

func (*Socket) AddRoom

func (ctx *Socket) AddRoom(room string)

AddRoom for user

func (*Socket) CicleEvents

func (ctx *Socket) CicleEvents()

CicleEvents init conection

func (*Socket) CloseSignal

func (ctx *Socket) CloseSignal() error

CloseSignal websocket connection

func (*Socket) Event

func (ctx *Socket) Event(eventName string, handler func(interface{}))

Event read message and parse

func (*Socket) ForceClose

func (ctx *Socket) ForceClose()

ForceClose websocket disconnection

func (*Socket) Read

func (ctx *Socket) Read() ([]byte, error)

Read read message and parse

func (*Socket) ReadMessage

func (ctx *Socket) ReadMessage() (*Message, error)

ReadMessage read message and parse

func (*Socket) Send

func (ctx *Socket) Send(event string, d interface{}) error

Send write messaga and send

func (*Socket) WCFG

func (ctx *Socket) WCFG(mode string, data interface{}) error

WCFG read message and parse

func (*Socket) WLOG

func (ctx *Socket) WLOG(data interface{}) error

WLOG read message and send

func (*Socket) WLOGISTRUE

func (ctx *Socket) WLOGISTRUE(boolVar bool, data interface{}) bool

WLOGISTRUE read message and send if true

type Upgrader

type Upgrader struct {
	websocket.Upgrader
	// contains filtered or unexported fields
}

Upgrader model for message

func (*Upgrader) ChangeID

func (ctx *Upgrader) ChangeID(user *Socket, newID string) (change bool)

ChangeID to user

func (*Upgrader) ChangeIDReconection

func (ctx *Upgrader) ChangeIDReconection(user *Socket, newID string) (change bool)

ChangeID to user

func (*Upgrader) GetUser

func (ctx *Upgrader) GetUser(ID string) (err error, user *Socket)

GetUser by ID

func (*Upgrader) Send

func (ctx *Upgrader) Send(event string, data interface{}, room string)

Send write json to all users

func (*Upgrader) SendArray

func (ctx *Upgrader) SendArray(room string, message []Message) []error

SendArray write json to all users

func (*Upgrader) SendMasive

func (ctx *Upgrader) SendMasive(event string, data interface{}, notSend ...*Socket)

SendMasive write json to all users

func (*Upgrader) Users

func (ctx *Upgrader) Users() []*Socket

Users get connect users

func (*Upgrader) UsersInRoom

func (ctx *Upgrader) UsersInRoom(room string) []*Socket

UsersInRoom get users in room

func (*Upgrader) WCFG

func (ctx *Upgrader) WCFG(mode string, data interface{}, room string)

WCFG write message to all users

func (*Upgrader) WLOG

func (ctx *Upgrader) WLOG(data interface{}, room string)

WLOG write log to all users

Jump to

Keyboard shortcuts

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