tmpchat

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 10 Imported by: 0

README

TmpChat - A Temporary Web Chat Application

TmpChat is a lightweight, real-time web chat application built with Go and WebSockets, designed to be easily deployed using Caddy web server. It provides a simple and clean interface for users to join chat rooms and communicate in real-time.

Features

  • Real-time messaging using WebSockets
  • User presence (shows when users join/leave)
  • Online user count
  • Responsive design that works on desktop and mobile
  • Simple deployment with Caddy
  • No database required - all data is stored in memory

Prerequisites

  • Go 1.24 or higher
  • Caddy v2

Deployment

  1. Build with xcaddy:

    xcaddy build --with github.com/jxskiss/caddy-tmpchat
    
  2. Edit your Caddyfile to configure tmpchat:

    yourdomain.com {
        route /chat {
            tmpchat
        }
    }
    
  3. Run Caddy:

    caddy run --config Caddyfile
    

Open https://yourdomain.com/chat to start chatting!

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Documentation

Index

Constants

View Source
const (
	MsgTypeOnline  = "online"
	MsgTypeOffline = "offline"
	MsgTypeChat    = "chat"
	MsgTypeSystem  = "system"
)

Message type constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatServer

type ChatServer struct {
	// contains filtered or unexported fields
}

ChatServer maintains the set of active clients and broadcasts messages to all clients

func NewChatServer

func NewChatServer() *ChatServer

NewChatServer creates a new server

func (*ChatServer) Close

func (s *ChatServer) Close()

Close shutdown the ChatServer

func (*ChatServer) Run

func (s *ChatServer) Run()

Run starts the ChatServer

type Client

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

Client represents a connected user

type Message

type Message struct {
	Type      string `json:"type"`
	Content   string `json:"content,omitempty"`
	Username  string `json:"username,omitempty"`
	Timestamp int64  `json:"timestamp,omitempty"`
	OnlineNum int    `json:"online_num"`
}

Message structure

type TempChat

type TempChat struct {
	// contains filtered or unexported fields
}

func (TempChat) CaddyModule

func (TempChat) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*TempChat) Cleanup

func (p *TempChat) Cleanup() error

Cleanup implements caddy.Cleanup

func (*TempChat) Provision

func (p *TempChat) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*TempChat) ServeHTTP

func (p *TempChat) ServeHTTP(w http.ResponseWriter, r *http.Request, _ caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*TempChat) UnmarshalCaddyfile

func (p *TempChat) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

func (*TempChat) Validate

func (p *TempChat) Validate() error

Validate implements caddy.Validator

Directories

Path Synopsis
internal
debug command
Package main is the entry point of the Caddy application.
Package main is the entry point of the Caddy application.

Jump to

Keyboard shortcuts

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