feat: add serveStatic middleware

This commit is contained in:
yangshangbo
2025-07-07 13:45:07 +08:00
parent a5bf8ebc7c
commit aca60cb4fa
10 changed files with 986 additions and 21 deletions
+8 -1
View File
@@ -1,6 +1,7 @@
module hono
import net.http
import net.urllib
// Context 结构体,类似 Hono.js 的实现
pub struct Context {
@@ -17,12 +18,18 @@ pub mut:
// Context 构造函数
pub fn Context.new(req http.Request, params map[string]string, query map[string]string, body string) Context {
// 解析URL获取路径
url := urllib.parse(req.url) or {
urllib.URL{
path: '/'
}
}
return Context{
req: req
params: params
query: query
body: body
url: req.url
url: url.path
headers: map[string]string{}
}
}