xonecas.io
8058
Ir

irvc / commit 76dea00

feat: initial agent gen and `irvc.md` doc

xonecas2026-10-11 76dea003b1e996a74186ac616b95fc19b822ce79

38 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

.gitignore+14−0
@@ -0,0 +1,14 @@
1+# Go
2+/irvc
3+*.exe
4+*.test
5+*.out
6+
7+# Node
8+node_modules/
9+web/dist/
10+
11+# Env
12+.env
13+.env.*
14+!.env.example
AGENTS.md+9−0
@@ -0,0 +1,9 @@
1+# Internet Relay Voice Chat
2+
3+> A WebRTC powered text and voice chat.
4+
5+Discord, Slack, and other chat and voice applications are expensive or gather user data.
6+With the lack of ownership of data, and more and more "enshitification" of these platforms,
7+the need is rising for a private self hosted instance of this.
8+
9+This is ours.
README.md+88−0
@@ -0,0 +1,88 @@
1+# IRVC — Internet Relay Voice Chat
2+
3+A WebRTC-powered text and voice chat. Private, self-hosted, personal server.
4+See [irvc.md](./irvc.md) for the design.
5+
6+## Architecture
7+
8+Three processes on one host:
9+
10+- **livekit-server** — voice only. Ephemeral rooms.
11+- **irvc** (this repo, Go) — API, auth, text chat over WebSocket, SQLite.
12+- **Caddy** — TLS + reverse proxy for the frontend, API, and LiveKit signal.
13+
14+## System dependencies
15+
16+Bare Linux, no Docker. On Arch:
17+
18+ sudo pacman -S go nodejs npm caddy
19+
20+`livekit-server` is not packaged on Arch. Install its release binary to
21+`~/.local/bin` (or `/usr/local/bin`) from the
22+[livekit releases](https://github.com/livekit/livekit/releases).
23+
24+## Build
25+
26+ go build -o irvc .
27+ cd web && npm install && npm run build
28+
29+`web/dist` is served by the Go process.
30+
31+## Configuration
32+
33+Secrets come from the shell env:
34+
35+| Var | Default | Notes |
36+| --- | --- | --- |
37+| `IRVC_LISTEN_ADDR` | `:8080` | |
38+| `IRVC_DB_PATH` | `irvc.db` | SQLite file, the only state |
39+| `IRVC_SESSION_SECRET` | — | **required**; signs session cookies |
40+| `IRVC_LIVEKIT_URL` | — | e.g. `wss://livekit.example.com` (browser-facing) |
41+| `IRVC_LIVEKIT_API_KEY` | — | must match livekit-server |
42+| `IRVC_LIVEKIT_SECRET` | — | must match livekit-server |
43+
44+Voice is disabled if the LiveKit vars are unset.
45+
46+Example `livekit.yaml` (run with `livekit-server --config livekit.yaml`):
47+
48+ port: 7880
49+ rtc:
50+ tcp_port: 7881
51+ port_range_start: 50000
52+ port_range_end: 60000
53+ use_external_ip: true
54+ keys:
55+ irvc: <IRVC_LIVEKIT_SECRET>
56+
57+## Invites
58+
59+Single-use, 14-day expiry. Create one:
60+
61+ ./irvc invite
62+
63+It prints the token and a `/join?token=...` link. Revoke = delete the row.
64+
65+## Run
66+
67+ export IRVC_SESSION_SECRET=...
68+ export IRVC_LIVEKIT_URL=wss://livekit.example.com
69+ export IRVC_LIVEKIT_API_KEY=irvc
70+ export IRVC_LIVEKIT_SECRET=...
71+ ./irvc
72+
73+Caddy terminates TLS and proxies both hosts to their local ports:
74+
75+ irvc.example.com {
76+ reverse_proxy 127.0.0.1:8080
77+ }
78+
79+ livekit.example.com {
80+ reverse_proxy 127.0.0.1:7880
81+ }
82+
83+Media ports (`7881/tcp`, `50000-60000/udp`) are exposed raw, not proxied;
84+open them in the host firewall.
85+
86+## Service
87+
88+Run both under systemd so they start on boot and restart on crash.
auth.go+320−0
@@ -0,0 +1,320 @@
1+package main
2+
3+import (
4+ "crypto/hmac"
5+ "crypto/rand"
6+ "crypto/sha256"
7+ "crypto/subtle"
8+ "database/sql"
9+ "encoding/base64"
10+ "net/http"
11+ "strings"
12+ "sync"
13+ "time"
14+
15+ "github.com/gin-gonic/gin"
16+ "golang.org/x/crypto/argon2"
17+)
18+
19+const (
20+ cookieName = "irvc_session"
21+ sessionTTL = 30 * 24 * time.Hour
22+ inviteTTL = 14 * 24 * time.Hour
23+ argonTime = 1
24+ argonMemory = 64 * 1024
25+ argonThreads = 4
26+ argonKeyLen = 32
27+ minPassword = 8
28+ maxMessageLen = 4000
29+)
30+
31+func randToken() string {
32+ b := make([]byte, 32)
33+ if _, err := rand.Read(b); err != nil {
34+ panic(err)
35+ }
36+ return base64.RawURLEncoding.EncodeToString(b)
37+}
38+
39+func hashPassword(pw string) string {
40+ salt := make([]byte, 16)
41+ if _, err := rand.Read(salt); err != nil {
42+ panic(err)
43+ }
44+ key := argon2.IDKey([]byte(pw), salt, argonTime, argonMemory, argonThreads, argonKeyLen)
45+ return base64.RawStdEncoding.EncodeToString(salt) + "$" + base64.RawStdEncoding.EncodeToString(key)
46+}
47+
48+func checkPassword(pw, encoded string) bool {
49+ saltB64, keyB64, ok := strings.Cut(encoded, "$")
50+ if !ok {
51+ return false
52+ }
53+ salt, err1 := base64.RawStdEncoding.DecodeString(saltB64)
54+ want, err2 := base64.RawStdEncoding.DecodeString(keyB64)
55+ if err1 != nil || err2 != nil {
56+ return false
57+ }
58+ got := argon2.IDKey([]byte(pw), salt, argonTime, argonMemory, argonThreads, argonKeyLen)
59+ return subtle.ConstantTimeCompare(got, want) == 1
60+}
61+
62+func (s *Server) sign(token string) string {
63+ mac := hmac.New(sha256.New, []byte(s.cfg.SessionSecret))
64+ mac.Write([]byte(token))
65+ return token + "." + base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
66+}
67+
68+func (s *Server) verifyToken(signed string) (string, bool) {
69+ token, sig, ok := strings.Cut(signed, ".")
70+ if !ok {
71+ return "", false
72+ }
73+ mac := hmac.New(sha256.New, []byte(s.cfg.SessionSecret))
74+ mac.Write([]byte(token))
75+ if subtle.ConstantTimeCompare([]byte(sig), []byte(base64.RawURLEncoding.EncodeToString(mac.Sum(nil)))) != 1 {
76+ return "", false
77+ }
78+ return token, true
79+}
80+
81+func (s *Server) setSession(c *gin.Context, userID int64) error {
82+ token := randToken()
83+ expires := time.Now().Add(sessionTTL)
84+ if _, err := s.db.Exec(
85+ `INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)`,
86+ token, userID, expires.Unix(),
87+ ); err != nil {
88+ return err
89+ }
90+ http.SetCookie(c.Writer, &http.Cookie{
91+ Name: cookieName,
92+ Value: s.sign(token),
93+ Path: "/",
94+ Expires: expires,
95+ HttpOnly: true,
96+ Secure: true,
97+ SameSite: http.SameSiteLaxMode,
98+ })
99+ return nil
100+}
101+
102+func (s *Server) currentUser(c *gin.Context) (User, bool) {
103+ cookie, err := c.Cookie(cookieName)
104+ if err != nil {
105+ return User{}, false
106+ }
107+ token, ok := s.verifyToken(cookie)
108+ if !ok {
109+ return User{}, false
110+ }
111+ var u User
112+ err = s.db.QueryRow(
113+ `SELECT u.id, u.username, u.created_at FROM sessions s JOIN users u ON u.id = s.user_id
114+ WHERE s.id = ? AND s.expires_at > ?`,
115+ token, time.Now().Unix(),
116+ ).Scan(&u.ID, &u.Username, &u.CreatedAt)
117+ if err != nil {
118+ return User{}, false
119+ }
120+ return u, true
121+}
122+
123+func (s *Server) requireAuth(c *gin.Context) {
124+ u, ok := s.currentUser(c)
125+ if !ok {
126+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
127+ return
128+ }
129+ c.Set("user", u)
130+ s.db.Exec(`DELETE FROM sessions WHERE expires_at <= ?`, time.Now().Unix())
131+ c.Next()
132+}
133+
134+type loginRequest struct {
135+ Username string `json:"username"`
136+ Password string `json:"password"`
137+}
138+
139+func (s *Server) handleLogin(c *gin.Context) {
140+ var req loginRequest
141+ if err := c.ShouldBindJSON(&req); err != nil {
142+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request"})
143+ return
144+ }
145+ var u User
146+ err := s.db.QueryRow(
147+ `SELECT id, username, pass_hash, created_at FROM users WHERE username = ?`,
148+ req.Username,
149+ ).Scan(&u.ID, &u.Username, &u.PassHash, &u.CreatedAt)
150+ if err != nil || !checkPassword(req.Password, u.PassHash) {
151+ c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid username or password"})
152+ return
153+ }
154+ if err := s.setSession(c, u.ID); err != nil {
155+ c.JSON(http.StatusInternalServerError, gin.H{"error": "session"})
156+ return
157+ }
158+ c.JSON(http.StatusOK, u)
159+}
160+
161+func (s *Server) handleLogout(c *gin.Context) {
162+ if cookie, err := c.Cookie(cookieName); err == nil {
163+ if token, ok := s.verifyToken(cookie); ok {
164+ s.db.Exec(`DELETE FROM sessions WHERE id = ?`, token)
165+ }
166+ }
167+ http.SetCookie(c.Writer, &http.Cookie{Name: cookieName, Value: "", Path: "/", MaxAge: -1})
168+ c.Status(http.StatusNoContent)
169+}
170+
171+func (s *Server) handleMe(c *gin.Context) {
172+ c.JSON(http.StatusOK, c.MustGet("user").(User))
173+}
174+
175+type userSummary struct {
176+ ID int64 `json:"id"`
177+ Username string `json:"username"`
178+}
179+
180+func (s *Server) handleUsers(c *gin.Context) {
181+ rows, err := s.db.Query(`SELECT id, username FROM users ORDER BY username`)
182+ if err != nil {
183+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
184+ return
185+ }
186+ defer rows.Close()
187+ users := []userSummary{}
188+ for rows.Next() {
189+ var u userSummary
190+ if err := rows.Scan(&u.ID, &u.Username); err != nil {
191+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
192+ return
193+ }
194+ users = append(users, u)
195+ }
196+ c.JSON(http.StatusOK, users)
197+}
198+
199+type claimRequest struct {
200+ Token string `json:"token"`
201+ Username string `json:"username"`
202+ Password string `json:"password"`
203+}
204+
205+func validUsername(name string) bool {
206+ if len(name) < 3 || len(name) > 32 {
207+ return false
208+ }
209+ for _, r := range name {
210+ ok := r == '_' || r == '-' || (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9')
211+ if !ok {
212+ return false
213+ }
214+ }
215+ return true
216+}
217+
218+func (s *Server) handleClaim(c *gin.Context) {
219+ var req claimRequest
220+ if err := c.ShouldBindJSON(&req); err != nil {
221+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request"})
222+ return
223+ }
224+ if !validUsername(req.Username) || len(req.Password) < minPassword {
225+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid username or password too short"})
226+ return
227+ }
228+ tx, err := s.db.Begin()
229+ if err != nil {
230+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
231+ return
232+ }
233+ defer tx.Rollback()
234+
235+ var usedBy sql.NullInt64
236+ var expires int64
237+ err = tx.QueryRow(`SELECT used_by, expires_at FROM invites WHERE token = ?`, req.Token).Scan(&usedBy, &expires)
238+ if err != nil || usedBy.Valid || expires < time.Now().Unix() {
239+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid or expired invite"})
240+ return
241+ }
242+ res, err := tx.Exec(
243+ `INSERT INTO users (username, pass_hash, created_at) VALUES (?, ?, ?)`,
244+ req.Username, hashPassword(req.Password), time.Now().Unix(),
245+ )
246+ if err != nil {
247+ c.JSON(http.StatusConflict, gin.H{"error": "username taken"})
248+ return
249+ }
250+ userID, _ := res.LastInsertId()
251+ if _, err := tx.Exec(
252+ `UPDATE invites SET used_by = ?, used_at = ? WHERE token = ?`,
253+ userID, time.Now().Unix(), req.Token,
254+ ); err != nil {
255+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
256+ return
257+ }
258+ if err := tx.Commit(); err != nil {
259+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
260+ return
261+ }
262+ if err := s.setSession(c, userID); err != nil {
263+ c.JSON(http.StatusInternalServerError, gin.H{"error": "session"})
264+ return
265+ }
266+ c.JSON(http.StatusOK, User{ID: userID, Username: req.Username, CreatedAt: time.Now().Unix()})
267+}
268+
269+func (s *Server) handleInviteInfo(c *gin.Context) {
270+ var usedBy sql.NullInt64
271+ var expires int64
272+ err := s.db.QueryRow(
273+ `SELECT used_by, expires_at FROM invites WHERE token = ?`, c.Param("token"),
274+ ).Scan(&usedBy, &expires)
275+ if err != nil || usedBy.Valid || expires < time.Now().Unix() {
276+ c.JSON(http.StatusNotFound, gin.H{"error": "invalid or expired invite"})
277+ return
278+ }
279+ c.JSON(http.StatusOK, gin.H{"valid": true})
280+}
281+
282+type rateLimiter struct {
283+ mu sync.Mutex
284+ hits map[string][]time.Time
285+ limit int
286+ window time.Duration
287+}
288+
289+func newRateLimiter(limit int, window time.Duration) *rateLimiter {
290+ return &rateLimiter{hits: map[string][]time.Time{}, limit: limit, window: window}
291+}
292+
293+func (rl *rateLimiter) allow(key string) bool {
294+ rl.mu.Lock()
295+ defer rl.mu.Unlock()
296+ now := time.Now()
297+ cutoff := now.Add(-rl.window)
298+ kept := rl.hits[key][:0]
299+ for _, t := range rl.hits[key] {
300+ if t.After(cutoff) {
301+ kept = append(kept, t)
302+ }
303+ }
304+ rl.hits[key] = kept
305+ if len(kept) >= rl.limit {
306+ return false
307+ }
308+ rl.hits[key] = append(kept, now)
309+ return true
310+}
311+
312+func (s *Server) rateLimited(rl *rateLimiter) gin.HandlerFunc {
313+ return func(c *gin.Context) {
314+ if !rl.allow(c.ClientIP()) {
315+ c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{"error": "too many requests"})
316+ return
317+ }
318+ c.Next()
319+ }
320+}
channels.go+112−0
@@ -0,0 +1,112 @@
1+package main
2+
3+import (
4+ "database/sql"
5+ "net/http"
6+ "strconv"
7+ "strings"
8+ "time"
9+
10+ "github.com/gin-gonic/gin"
11+)
12+
13+func (s *Server) handleChannels(c *gin.Context) {
14+ rows, err := s.db.Query(`SELECT id, type, name, position FROM channels ORDER BY position, id`)
15+ if err != nil {
16+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
17+ return
18+ }
19+ defer rows.Close()
20+ channels := []Channel{}
21+ for rows.Next() {
22+ var ch Channel
23+ if err := rows.Scan(&ch.ID, &ch.Type, &ch.Name, &ch.Position); err != nil {
24+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
25+ return
26+ }
27+ channels = append(channels, ch)
28+ }
29+ c.JSON(http.StatusOK, channels)
30+}
31+
32+func (s *Server) handleMessages(c *gin.Context) {
33+ channelID, err := strconv.ParseInt(c.Param("id"), 10, 64)
34+ if err != nil {
35+ c.JSON(http.StatusBadRequest, gin.H{"error": "bad channel"})
36+ return
37+ }
38+ rows, err := s.db.Query(
39+ `SELECT m.id, m.channel_id, m.user_id, u.username, m.body, m.created_at
40+ FROM messages m JOIN users u ON u.id = m.user_id
41+ WHERE m.channel_id = ? ORDER BY m.id DESC LIMIT 200`,
42+ channelID,
43+ )
44+ if err != nil {
45+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
46+ return
47+ }
48+ defer rows.Close()
49+ messages := []Message{}
50+ for rows.Next() {
51+ var m Message
52+ if err := rows.Scan(&m.ID, &m.ChannelID, &m.UserID, &m.Username, &m.Body, &m.CreatedAt); err != nil {
53+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
54+ return
55+ }
56+ messages = append(messages, m)
57+ }
58+ // reverse to chronological order
59+ for i, j := 0, len(messages)-1; i < j; i, j = i+1, j-1 {
60+ messages[i], messages[j] = messages[j], messages[i]
61+ }
62+ c.JSON(http.StatusOK, messages)
63+}
64+
65+type sendMessageRequest struct {
66+ Body string `json:"body"`
67+}
68+
69+func (s *Server) handleSendMessage(c *gin.Context) {
70+ channelID, err := strconv.ParseInt(c.Param("id"), 10, 64)
71+ if err != nil {
72+ c.JSON(http.StatusBadRequest, gin.H{"error": "bad channel"})
73+ return
74+ }
75+ var req sendMessageRequest
76+ if err := c.ShouldBindJSON(&req); err != nil {
77+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request"})
78+ return
79+ }
80+ body := strings.TrimSpace(req.Body)
81+ if body == "" || len(body) > maxMessageLen {
82+ c.JSON(http.StatusBadRequest, gin.H{"error": "invalid message"})
83+ return
84+ }
85+ user := c.MustGet("user").(User)
86+ var channelType string
87+ if err := s.db.QueryRow(`SELECT type FROM channels WHERE id = ?`, channelID).Scan(&channelType); err != nil {
88+ if err == sql.ErrNoRows {
89+ c.JSON(http.StatusNotFound, gin.H{"error": "channel not found"})
90+ return
91+ }
92+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
93+ return
94+ }
95+ if channelType != "text" {
96+ c.JSON(http.StatusBadRequest, gin.H{"error": "not a text channel"})
97+ return
98+ }
99+ now := time.Now().Unix()
100+ res, err := s.db.Exec(
101+ `INSERT INTO messages (channel_id, user_id, body, created_at) VALUES (?, ?, ?, ?)`,
102+ channelID, user.ID, body, now,
103+ )
104+ if err != nil {
105+ c.JSON(http.StatusInternalServerError, gin.H{"error": "db"})
106+ return
107+ }
108+ id, _ := res.LastInsertId()
109+ msg := Message{ID: id, ChannelID: channelID, UserID: user.ID, Username: user.Username, Body: body, CreatedAt: now}
110+ s.hub.broadcast(event{Type: "message", Message: &msg})
111+ c.JSON(http.StatusOK, msg)
112+}
config.go+30−0
@@ -0,0 +1,30 @@
1+package main
2+
3+import "os"
4+
5+type Config struct {
6+ ListenAddr string
7+ DBPath string
8+ SessionSecret string
9+ LiveKitURL string
10+ LiveKitKey string
11+ LiveKitSecret string
12+}
13+
14+func LoadConfig() *Config {
15+ return &Config{
16+ ListenAddr: env("IRVC_LISTEN_ADDR", ":8080"),
17+ DBPath: env("IRVC_DB_PATH", "irvc.db"),
18+ SessionSecret: env("IRVC_SESSION_SECRET", ""),
19+ LiveKitURL: env("IRVC_LIVEKIT_URL", ""),
20+ LiveKitKey: env("IRVC_LIVEKIT_API_KEY", ""),
21+ LiveKitSecret: env("IRVC_LIVEKIT_SECRET", ""),
22+ }
23+}
24+
25+func env(key, def string) string {
26+ if v := os.Getenv(key); v != "" {
27+ return v
28+ }
29+ return def
30+}
db.go+110−0
@@ -0,0 +1,110 @@
1+package main
2+
3+import (
4+ "database/sql"
5+ "log"
6+ "time"
7+
8+ _ "modernc.org/sqlite"
9+)
10+
11+type User struct {
12+ ID int64 `json:"id"`
13+ Username string `json:"username"`
14+ PassHash string `json:"-"`
15+ CreatedAt int64 `json:"createdAt"`
16+}
17+
18+type Channel struct {
19+ ID int64 `json:"id"`
20+ Type string `json:"type"`
21+ Name string `json:"name"`
22+ Position int `json:"position"`
23+}
24+
25+type Message struct {
26+ ID int64 `json:"id"`
27+ ChannelID int64 `json:"channelId"`
28+ UserID int64 `json:"userId"`
29+ Username string `json:"username"`
30+ Body string `json:"body"`
31+ CreatedAt int64 `json:"createdAt"`
32+}
33+
34+func OpenDB(path string) *sql.DB {
35+ dsn := path + "?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)&_pragma=foreign_keys(1)"
36+ db, err := sql.Open("sqlite", dsn)
37+ if err != nil {
38+ log.Fatalf("open db: %v", err)
39+ }
40+ if err := db.Ping(); err != nil {
41+ log.Fatalf("ping db: %v", err)
42+ }
43+ migrate(db)
44+ return db
45+}
46+
47+const schema = `
48+CREATE TABLE IF NOT EXISTS users (
49+ id INTEGER PRIMARY KEY AUTOINCREMENT,
50+ username TEXT NOT NULL UNIQUE,
51+ pass_hash TEXT NOT NULL,
52+ created_at INTEGER NOT NULL
53+);
54+CREATE TABLE IF NOT EXISTS invites (
55+ token TEXT PRIMARY KEY,
56+ created_by INTEGER,
57+ expires_at INTEGER NOT NULL,
58+ used_by INTEGER,
59+ used_at INTEGER
60+);
61+CREATE TABLE IF NOT EXISTS sessions (
62+ id TEXT PRIMARY KEY,
63+ user_id INTEGER NOT NULL,
64+ expires_at INTEGER NOT NULL
65+);
66+CREATE TABLE IF NOT EXISTS channels (
67+ id INTEGER PRIMARY KEY AUTOINCREMENT,
68+ type TEXT NOT NULL,
69+ name TEXT NOT NULL,
70+ position INTEGER NOT NULL,
71+ created_at INTEGER NOT NULL
72+);
73+CREATE TABLE IF NOT EXISTS messages (
74+ id INTEGER PRIMARY KEY AUTOINCREMENT,
75+ channel_id INTEGER NOT NULL,
76+ user_id INTEGER NOT NULL,
77+ body TEXT NOT NULL,
78+ created_at INTEGER NOT NULL
79+);
80+CREATE INDEX IF NOT EXISTS idx_messages_channel ON messages(channel_id, id);
81+`
82+
83+func migrate(db *sql.DB) {
84+ if _, err := db.Exec(schema); err != nil {
85+ log.Fatalf("migrate: %v", err)
86+ }
87+ var n int
88+ if err := db.QueryRow(`SELECT COUNT(*) FROM channels`).Scan(&n); err != nil {
89+ log.Fatalf("count channels: %v", err)
90+ }
91+ if n > 0 {
92+ return
93+ }
94+ now := time.Now().Unix()
95+ seed := []struct {
96+ kind, name string
97+ pos int
98+ }{
99+ {"text", "general", 0},
100+ {"voice", "general", 1},
101+ }
102+ for _, c := range seed {
103+ if _, err := db.Exec(
104+ `INSERT INTO channels (type, name, position, created_at) VALUES (?, ?, ?, ?)`,
105+ c.kind, c.name, c.pos, now,
106+ ); err != nil {
107+ log.Fatalf("seed channels: %v", err)
108+ }
109+ }
110+}
go.mod+48−0
@@ -0,0 +1,48 @@
1+module irvc
2+
3+go 1.27
4+
5+require (
6+ github.com/gin-gonic/gin v1.12.0
7+ github.com/gorilla/websocket v1.5.3
8+ golang.org/x/crypto v0.58.0
9+ modernc.org/sqlite v1.60.1
10+)
11+
12+require (
13+ github.com/bytedance/gopkg v0.1.3 // indirect
14+ github.com/bytedance/sonic v1.15.0 // indirect
15+ github.com/bytedance/sonic/loader v0.5.0 // indirect
16+ github.com/cloudwego/base64x v0.1.6 // indirect
17+ github.com/dustin/go-humanize v1.0.1 // indirect
18+ github.com/gabriel-vasile/mimetype v1.4.12 // indirect
19+ github.com/gin-contrib/sse v1.1.0 // indirect
20+ github.com/go-playground/locales v0.14.1 // indirect
21+ github.com/go-playground/universal-translator v0.18.1 // indirect
22+ github.com/go-playground/validator/v10 v10.30.1 // indirect
23+ github.com/goccy/go-json v0.10.5 // indirect
24+ github.com/goccy/go-yaml v1.19.2 // indirect
25+ github.com/google/uuid v1.6.0 // indirect
26+ github.com/json-iterator/go v1.1.12 // indirect
27+ github.com/klauspost/cpuid/v2 v2.3.0 // indirect
28+ github.com/leodido/go-urn v1.4.0 // indirect
29+ github.com/mattn/go-isatty v0.0.24 // indirect
30+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
31+ github.com/modern-go/reflect2 v1.0.2 // indirect
32+ github.com/ncruces/go-strftime v1.0.0 // indirect
33+ github.com/pelletier/go-toml/v2 v2.2.4 // indirect
34+ github.com/quic-go/qpack v0.6.0 // indirect
35+ github.com/quic-go/quic-go v0.59.0 // indirect
36+ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
37+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
38+ github.com/ugorji/go/codec v1.3.1 // indirect
39+ go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
40+ golang.org/x/arch v0.22.0 // indirect
41+ golang.org/x/net v0.60.0 // indirect
42+ golang.org/x/sys v0.49.0 // indirect
43+ golang.org/x/text v0.43.0 // indirect
44+ google.golang.org/protobuf v1.36.10 // indirect
45+ modernc.org/libc v1.77.1 // indirect
46+ modernc.org/mathutil v1.7.1 // indirect
47+ modernc.org/memory v1.12.1 // indirect
48+)
go.sum+136−0
@@ -0,0 +1,136 @@
1+github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
2+github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
3+github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE=
4+github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k=
5+github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE=
6+github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
7+github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
8+github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
9+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
11+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
13+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
14+github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
15+github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
16+github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
17+github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
18+github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
19+github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
20+github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
21+github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
22+github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
23+github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
24+github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
25+github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
26+github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
27+github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
28+github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
29+github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
30+github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
31+github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
32+github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
33+github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
34+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
35+github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 h1:LMLX+LgTNWpfvCBdFebv6EsYotImrt/Ppc5cXIriCSo=
36+github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk=
37+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
38+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
39+github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
40+github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
41+github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
42+github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
43+github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
44+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
45+github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
46+github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
47+github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
48+github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
49+github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
50+github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
51+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
52+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
53+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
54+github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
55+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
56+github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
57+github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
58+github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
59+github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
60+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
61+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
62+github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
63+github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
64+github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
65+github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
66+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
67+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
68+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
69+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
70+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
71+github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
72+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
73+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
74+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
75+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
76+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
77+github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
78+github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
79+github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
80+github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
81+github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
82+github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
83+go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
84+go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
85+go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
86+go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
87+golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI=
88+golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
89+golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54=
90+golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w=
91+golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
92+golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
93+golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
94+golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
95+golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
96+golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
97+golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
98+golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
99+golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
100+golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
101+golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI=
102+golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA=
103+google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
104+google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
105+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
106+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
107+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
108+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
109+modernc.org/cc/v4 v4.29.7 h1:q+NXGJ0bK3b4TXFYQQVr9pYETGnmwFWkrUzJnMya/Tg=
110+modernc.org/cc/v4 v4.29.7/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
111+modernc.org/ccgo/v4 v4.36.1 h1:ZNIUZAryN0UgnJwtyxrdEzcFc3yD4Cu4AzjfPXsLsIE=
112+modernc.org/ccgo/v4 v4.36.1/go.mod h1:rrtGc2QkS239nYb/mQNuBMyjq3/y3ZXWbBjPoV3wqzA=
113+modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
114+modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
115+modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
116+modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
117+modernc.org/gc/v3 v3.1.5 h1:21ldfPfRYE31Tb7B3mwAK8gy1AxP4+dKjrOQPfqakoc=
118+modernc.org/gc/v3 v3.1.5/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
119+modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
120+modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
121+modernc.org/libc v1.77.1 h1:Ct8j47QtiZ1Enj2DtFXQtUqrPCAjdCmPjtCuvrYQ0Hs=
122+modernc.org/libc v1.77.1/go.mod h1:87/pZ4L6nD1zqW4nItuS12YO7hN1igAah34xjnQo/W0=
123+modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
124+modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
125+modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g=
126+modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
127+modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
128+modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
129+modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
130+modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
131+modernc.org/sqlite v1.60.1 h1:/blz53O951KWFOso4QQvEs/Fq6cDBKLtMVrYNSeJVKw=
132+modernc.org/sqlite v1.60.1/go.mod h1:1dIoEagfDE72QytD5scH1lxARtaUgKgHC/NuApA27r0=
133+modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
134+modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
135+modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
136+modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
irvc.md+95−0
@@ -0,0 +1,95 @@
1+# IRVC — Design
2+
3+A WebRTC-powered text and voice chat. Private, self-hosted, personal server.
4+
5+## Goal
6+
7+Small, private chat + voice for 4–6 people on one VPS. No data gathering, full ownership.
8+
9+## Scope (MVP)
10+
11+**In:**
12+- Server-side accounts, invite-only.
13+- Text channels with persisted history (IRC-like).
14+- Voice channels, ephemeral (not recorded).
15+- Presence: online/offline.
16+- One server per deployment, seeded with one text and one voice channel.
17+
18+**Out (now):**
19+- Large scale, multi-node, clustering.
20+- Recording, screen share, DMs.
21+- Email, OAuth, passkeys.
22+- Docker.
23+- Backups.
24+- Password reset via email (admin resets manually).
25+
26+## Architecture
27+
28+One VPS, three processes:
29+
30+- **LiveKit** — self-hosted, voice only. Own ports: signal `7880`, TCP `7881`, media `50000-60000/udp`. Media ports exposed raw, not proxied.
31+- **Gin server (Go)** — API, auth, invite/session handling, token minting, text chat over WebSocket, SQLite.
32+- **Caddy** — TLS + reverse proxy for frontend and API. Terminates TLS; proxies `wss` to LiveKit signal.
33+
34+Split:
35+- Text → our WebSocket + SQLite. LiveKit not involved.
36+- Voice → LiveKit. Ephemeral.
37+- Presence → our WebSocket (connected = online).
38+
39+## Auth & Identity
40+
41+- Invite links: single-use, 14-day expiry. Anyone with a link creates a user and joins.
42+- Revoke = delete the row.
43+- Passwords hashed with argon2id.
44+- Login → session cookie (`HttpOnly`, `Secure`, `SameSite=Lax`) → server mints a short-lived LiveKit token when a voice channel is joined.
45+- Rate limit login and invite-claim endpoints.
46+- No email. Admin resets passwords by hand.
47+
48+## Data (SQLite)
49+
50+WAL mode, `busy_timeout`. One file, the only state.
51+
52+```
53+users (id, username, pass_hash, created_at)
54+invites (token, created_by, expires_at, used_by, used_at)
55+sessions (id, user_id, expires_at)
56+channels (id, type, name, position, created_at) -- type: text | voice
57+messages (id, channel_id, user_id, body, created_at)
58+```
59+
60+Seed: one text channel `#general`, one voice channel `general`.
61+
62+## Behavior
63+
64+- **Channels:** seeded only (`#general` text, `general` voice). Ordered by `position`. CRUD is out of scope for now.
65+- **Text:** messages persist; shown as timestamp, author, content. Live append over WS.
66+- **Voice:** joining a voice channel connects to its LiveKit room. Not persisted, not recorded.
67+- **Presence:** a user is online while their WS connection is up; otherwise offline. No invisible mode.
68+
69+## Frontend
70+
71+- React, modern. oxlint + oxfmt. Tailwind + Shadcn.
72+- Dark sepia theme (colors from `../www`), monospace, minimalist, functional.
73+- Layout:
74+ - Left sidebar: text channels, then voice channels.
75+ - Focus pane: selected item, or first text channel by default.
76+ - Right sidebar (toggleable): user list with online/offline.
77+
78+## Config
79+
80+Secrets from shell env, `IRVC_*`:
81+
82+```
83+IRVC_LISTEN_ADDR
84+IRVC_DB_PATH
85+IRVC_SESSION_SECRET
86+IRVC_LIVEKIT_URL
87+IRVC_LIVEKIT_API_KEY
88+IRVC_LIVEKIT_SECRET
89+```
90+
91+LiveKit key/secret must match the LiveKit server config and ours.
92+
93+## Deployment
94+
95+Bare Linux, no Docker. README lists system-level deps. Services start on boot and restart on crash (systemd).
main.go+96−0
@@ -0,0 +1,96 @@
1+package main
2+
3+import (
4+ "database/sql"
5+ "fmt"
6+ "log"
7+ "net/http"
8+ "os"
9+ "path/filepath"
10+ "strings"
11+ "time"
12+
13+ "github.com/gin-gonic/gin"
14+)
15+
16+type Server struct {
17+ cfg *Config
18+ db *sql.DB
19+ hub *hub
20+}
21+
22+func main() {
23+ cfg := LoadConfig()
24+ db := OpenDB(cfg.DBPath)
25+ defer db.Close()
26+
27+ if len(os.Args) > 1 && os.Args[1] == "invite" {
Cut short: this commit's diff is over 1000 lines.
voice.go+82−0
Cut short: this commit's diff is over 1000 lines.
web/components.json+25−0
Cut short: this commit's diff is over 1000 lines.
web/index.html+17−0
Cut short: this commit's diff is over 1000 lines.
web/package-lock.json+8485−0
Cut short: this commit's diff is over 1000 lines.
web/package.json+38−0
Cut short: this commit's diff is over 1000 lines.
web/src/App.tsx+38−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/AuthShell.tsx+23−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/ChatPane.tsx+69−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/Sidebar.tsx+67−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/UserList.tsx+31−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/VoiceRoom.tsx+104−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/ui/button.tsx+66−0
Cut short: this commit's diff is over 1000 lines.
web/src/components/ui/input.tsx+18−0
Cut short: this commit's diff is over 1000 lines.
web/src/index.css+125−0
Cut short: this commit's diff is over 1000 lines.
web/src/lib/api.ts+13−0
Cut short: this commit's diff is over 1000 lines.
web/src/lib/types.ts+32−0
Cut short: this commit's diff is over 1000 lines.
web/src/lib/utils.ts+1−0
Cut short: this commit's diff is over 1000 lines.
web/src/main.tsx+5−0
Cut short: this commit's diff is over 1000 lines.
web/src/views/Chat.tsx+96−0
Cut short: this commit's diff is over 1000 lines.
web/src/views/Join.tsx+69−0
Cut short: this commit's diff is over 1000 lines.
web/src/views/Login.tsx+48−0
Cut short: this commit's diff is over 1000 lines.
web/src/vite-env.d.ts+1−0
Cut short: this commit's diff is over 1000 lines.
web/tsconfig.app.json+25−0
Cut short: this commit's diff is over 1000 lines.
web/tsconfig.json+9−0
Cut short: this commit's diff is over 1000 lines.
web/tsconfig.node.json+20−0
Cut short: this commit's diff is over 1000 lines.
web/vite.config.ts+22−0
Cut short: this commit's diff is over 1000 lines.
ws.go+176−0
Cut short: this commit's diff is over 1000 lines.