util

package
v0.0.0-...-25c2323 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	C2A = "client-to-all"
	C2S = "client-to-server"
	S2C = "server-to-client" // Server to single client broadcast
	S2A = "server-to-all"    // Global client broadcast
)

Variables

This section is empty.

Functions

func ClientToAll

func ClientToAll(clientMessage Message, conn *websocket.Conn)

func GetDateTime

func GetDateTime() string

Returns datetime in the format "2006-01-02 15:04:05"

Types

type Client

type Client struct {
	UrlAddr    string
	ConnStatus bool
	Conn       *websocket.Conn
	Username   string
	Message    Message
}

func (*Client) CheckServerMessage

func (client *Client) CheckServerMessage() (Message, error)

func (*Client) CloseConn

func (client *Client) CloseConn() error

Close the connection to the server Graceful disconnection

func (*Client) Connect

func (client *Client) Connect() error

func (*Client) Handshake

func (client *Client) Handshake() error

The first interchange of messages between the client and the server Or the handshake Used to setup the username and other config info

func (*Client) ListClients

func (client *Client) ListClients() error

Lists the clients online Only server-side for now

func (*Client) Run

func (client *Client) Run() error

Message transfer loop

func (*Client) Send2All

func (client *Client) Send2All(content string) error

Send a normal chat message to all the clients

func (*Client) SendMessageStruct

func (client *Client) SendMessageStruct() error

Send method to make the code a bit cleaner

func (*Client) SendMsgOrCmd

func (client *Client) SendMsgOrCmd(content string) error

Sends the Message struct to the Server Checks if command or message and sends appropriate config setup If command, content begins with ':'

type ClientError

type ClientError struct {
	Err    error
	Code   int
	Simple string
}

ClientError.Simple => Simple description of the error

func (*ClientError) Error

func (ce *ClientError) Error() string

type Message

type Message struct {
	Sender    string
	Direction string
	Config    string
	Content   string
	Password  string
	Timestamp string
}

Jump to

Keyboard shortcuts

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