gowssrv

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 4 Imported by: 0

README

Go-WS-Srv

Purpose

Go-WS-Srv it's just a small wrapper for Gorilla Websocket library that simplify clients connections process.

Dev version! Only for testing

Installation

go get github.com/hetacode/go-ws-srv

Example

package main

import (
	"log"

	gowssrv "github.com/hetacode/go-ws-srv"
)

func main() {
	s := gowssrv.NewServer(":8080", "/", gowssrv.ServerConfig{Origin: "*"})
	s.OnConnected = func(c *gowssrv.Client) {
		log.Printf("client %s OnConnected", c.ID)
	}
	s.OnMessage = func(c *gowssrv.Client, s string) {
		log.Printf("client %s msg: %s", c.ID, s)
	}
	s.OnDisconnected = func(c *gowssrv.Client) {
		log.Printf("client %s OnDisconnected", c.ID)
	}
	s.OnError = func(c *gowssrv.Client, e error) {
		log.Printf("client %s OnError %s", c.ID, e)
	}
	s.Serve()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID string
	// contains filtered or unexported fields
}

func (*Client) SendMessage

func (c *Client) SendMessage(msg string) error

type Server

type Server struct {
	OnConnected    func(*Client)
	OnMessage      func(*Client, string)
	OnError        func(*Client, error)
	OnDisconnected func(*Client)
	// contains filtered or unexported fields
}

func NewServer

func NewServer(address, endpoint string, config ServerConfig) *Server

func (*Server) Serve

func (s *Server) Serve()

type ServerConfig

type ServerConfig struct {
	Origin string // * - all (no check)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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