refc: Refactor project structure

This commit is contained in:
meiseayoung
2025-12-30 11:00:46 +08:00
parent 369655a9ea
commit 782a4e7795
106 changed files with 947 additions and 4184 deletions
+39
View File
@@ -0,0 +1,39 @@
// Middleware example for v-hono web framework
module main
import net.http
import time
import hono
fn main() {
mut app := hono.Hono.new()
// Logger middleware
app.use(fn (mut c hono.Context, next fn (mut hono.Context) http.Response) http.Response {
start := time.now()
response := next(mut c)
duration := time.since(start)
println('[${c.req.method}] ${c.path} - ${duration}')
return response
})
// CORS middleware
app.use(fn (mut c hono.Context, next fn (mut hono.Context) http.Response) http.Response {
c.headers['Access-Control-Allow-Origin'] = '*'
c.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
c.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization'
return next(mut c)
})
// Routes
app.get('/', fn (mut c hono.Context) http.Response {
return c.text('Hello with middleware!')
})
app.get('/api/data', fn (mut c hono.Context) http.Response {
return c.json('{"data": "some data"}')
})
println('Server starting on http://localhost:3000')
app.listen(':3000')
}