1. Cross-platform uSockets configuration - Use @VMODROOT for portable library paths - Support macOS (arm64/x86_64), Windows, and Linux - Auto-detect Homebrew paths for libuv on macOS 2. Route cache optimization (3x performance boost) - Replace LRU cache with FastRouteCache for dynamic routes - Zero-overhead cache lookup (no TTL check, no LRU reordering) - Dynamic route performance: 30k -> 97k RPS 3. New test files - Go-based integration tests for picoev and uSockets - FastCache optimization validation tests - Benchmark comparison tools
45 lines
994 B
V
45 lines
994 B
V
// uSockets 简化测试服务器 - 与外层 main.v 配置一致
|
|
module main
|
|
|
|
import hono
|
|
import net.http
|
|
import x.json2
|
|
|
|
// JSON 响应结构体
|
|
struct JsonResponse {
|
|
message string
|
|
}
|
|
|
|
struct UserResponse {
|
|
user_id string
|
|
}
|
|
|
|
fn main() {
|
|
mut app := hono.Hono.new()
|
|
|
|
// 与外层 main.v 完全一致的路由配置(无中间件)
|
|
app.get('/', fn (mut c hono.Context) http.Response {
|
|
return c.text('Hello, World!')
|
|
})
|
|
|
|
app.get('/json', fn (mut c hono.Context) http.Response {
|
|
data := JsonResponse{message: 'Hello, JSON!'}
|
|
json_str := json2.encode(data)
|
|
return c.json(json_str)
|
|
})
|
|
|
|
app.get('/users/:id', fn (mut c hono.Context) http.Response {
|
|
user_id := c.params['id'] or { 'unknown' }
|
|
data := UserResponse{user_id: user_id}
|
|
json_str := json2.encode(data)
|
|
return c.json(json_str)
|
|
})
|
|
|
|
app.get('/health', fn (mut c hono.Context) http.Response {
|
|
return c.text('OK')
|
|
})
|
|
|
|
println('[usockets-simple] Starting on port 9999 (uSockets)...')
|
|
app.listen_usockets(9999)
|
|
}
|