Categorygithub.com/vlad-olteanu/go-websocket-prefab
modulepackage
0.0.0-20211208214020-c661d4604239
Repository: https://github.com/vlad-olteanu/go-websocket-prefab.git
Documentation: pkg.go.dev

# README

Go WebSocket Prefab

A ready to deploy wrapper for the Gorilla WebSocket library

Installation

go get github.com/vlad-olteanu/go-websocket-prefab

Usage examples

Sample project

import (
    wsprefab "github.com/vlad-olteanu/go-websocket-prefab"
)

func onOpen(c *wsprefab.Client) { }
func onMessage(c *wsprefab.Client, message []byte) { }
func onClose(c *wsprefab.Client) { }
func main() {
	wsprefab.NewWebsocketServer("/wstest",
		onOpen, //optional, you can use nil instead
		onMessage,
		onClose, //optional
		&wsprefab.KwArgs{ //optional
			MaxMessageSize: 1024*1024*16,//bytes
		},
	)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Sending messages to the client

c.Send<-[]byte("Message")
c.Send<-jsonData

Storing information about the clients

c.Attribs["messageCount"]=0
c.Attribs["messageCount"]=c.Attribs["messageCount"].(int)+1

Closing the connection

c.Conn.Close()

Look here for a broadcast server example

# Packages

No description provided by the author

# Functions

No description provided by the author

# Structs

No description provided by the author
No description provided by the author
WebsocketServer Only instantiate using constructor!.