chat

import "gitlab.com/Alfred-Jijo/go-chat/src/chat"

Package chat handles the core business logic for the chat application, including WebSocket management, message broadcasting, and data structures.

Index

func BroadcastClear

func BroadcastClear()

BroadcastClear sends a special signal to all connected clients instructing them to wipe their local chat history UI.

func BroadcastLog

func BroadcastLog(prefix, text string)

BroadcastLog creates a system-level log message and sends it to the broadcast channel. These messages are typically displayed in the “Logs” tab of the frontend.

prefix: The label for the log (e.g., “SYSTEM”, “ERROR”). text: The actual log message content.

func ChatHandleConnections

func ChatHandleConnections(w http.ResponseWriter, r *http.Request)

ChatHandleConnections upgrades the HTTP connection to a WebSocket and manages the read-loop for a specific client. It listens for incoming JSON messages and pushes them to the broadcast channel.

func ChatHandleFileUpload

func ChatHandleFileUpload(w http.ResponseWriter, r *http.Request)

ChatHandleFileUpload accepts multipart form data containing a file. It saves the file to the local ‘uploads’ directory and broadcasts a file-link message to the chat.

It includes CORS headers to allow uploads from external domains (e.g., GitHub Pages).

func ChatHandleMessages

func ChatHandleMessages()

ChatHandleMessages runs as a Goroutine. It continuously reads from the broadcast channel and writes the message to every connected WebSocket client.

type Message

Message represents a single unit of communication in the chat. It maps directly to JSON sent over the WebSocket.

type Message struct {
    // Username is the display name of the sender.
    Username string `json:"username"`
    // Content is the actual text message or filename.
    Content string `json:"content"`
    // Type indicates the message category: "text", "file", "log", or "clear".
    Type string `json:"type"`
    // FileUrl is the relative path to the uploaded file (optional).
    FileUrl string `json:"file_url,omitempty"`
}

server

import "gitlab.com/Alfred-Jijo/go-chat/src/server"

Package main is the entry point for the chat server application. It configures the HTTP routes, static file serving, and starts the WebSocket handlers and admin console.

Index

func StartConsole

func StartConsole()

StartConsole initiates the interactive command-line interface for the server admin. It blocks the main thread, listening for standard input commands such as “clear-chat”, “purge”, or “shutdown”.

Generated by gomarkdoc