-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdoc.go
More file actions
68 lines (68 loc) · 2.15 KB
/
doc.go
File metadata and controls
68 lines (68 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Package velaros provides a lightweight, flexible WebSocket framework for Go.
//
// Velaros enables building real-time WebSocket applications with pattern-based
// message routing, composable middleware, and bidirectional communication patterns.
//
// # Key Features
//
// - Pattern-based routing with parameters and wildcards
// - Composable middleware for authentication, logging, and more
// - Bidirectional communication with Send, Request, and Receive methods
// - Context pooling for high performance
// - Automatic text/binary message type detection
// - Works with any HTTP router/framework via http.Handler interface
//
// # Quick Start
//
// Create a router, add middleware, and bind handlers to message paths:
//
// router := velaros.NewRouter()
// router.Use(json.Middleware())
//
// router.Bind("/chat/message", func(ctx *velaros.Context) {
// var msg ChatMessage
// ctx.ReceiveInto(&msg)
// ctx.Send(ChatResponse{Status: "received"})
// })
//
// http.ListenAndServe(":8080", router)
//
// # Message Format
//
// Message format is determined by middleware. The included JSON middleware
// expects messages with an ID (for request/reply) and path (for routing):
//
// {
// "id": "abc123",
// "path": "/chat/message",
// "username": "alice",
// "text": "Hello!"
// }
//
// # Routing
//
// Routes support exact paths, named parameters, and wildcards:
//
// router.Bind("/users/list", handler) // Exact match
// router.Bind("/users/:id", handler) // Named parameter
// router.Bind("/files/**", handler) // Wildcard
//
// # Middleware
//
// Middleware executes before handlers and can modify context, perform
// authentication, or short-circuit the chain:
//
// router.Use(func(ctx *velaros.Context) {
// log.Printf("Message: %s", ctx.Path())
// ctx.Next()
// })
//
// # Context Storage
//
// Store values at the message level (per-message) or socket level (per-connection):
//
// ctx.Set("requestTime", time.Now()) // Per-message
// ctx.SetOnSocket("username", "alice") // Per-connection
//
// For more examples and documentation, see https://github.com/RobertWHurst/velaros
package velaros