💻 代码示例
// 基本路由设置
mut app := hono.Hono.new()
// 静态文件服务
app.use(hono.serve_static_default())
app.use(hono.serve_static_path('/assets', './static'))
// 基础路由
app.get('/hello', fn (mut c hono.Context) http.Response {
return c.text('Hello, World!')
})
// 动态路由
app.get('/users/:id', fn (mut c hono.Context) http.Response {
user_id := c.params['id']
return c.json('{"user_id": "${user_id}"}')
})
// 文件服务
app.get('/file/:filename', fn (mut c hono.Context) http.Response {
filename := c.params['filename']
return c.file('public/${filename}')
})
// 启动服务器
app.listen(':8080')