有没有办法使用 fasthttp 框架来服务多个目录?我出于同样的目的编写了以下代码。但是,这段代码没有像我预期的那样工作。当我访问localhost:8080/path1时,它会引发错误和警告,
无法打开请求的路径
2017/10/13 16:57:01 0.977 #0000000100000001 - 127.0.0.1:8080<->127.0.0.1:48870 - GET http://localhost:8080/path1 - 无法打开文件“/home/test/path1” : 打开 /home/test/path1/path1: 没有这样的文件或目录
我不知道这个 url(/home/test/path1) 如何重定向到 (/home/test/path1/path1)。下面的代码有什么问题?
requestHandler := func(ctx *fasthttp.RequestCtx) {
var fs fasthttp.FS
switch string(ctx.Path()) {
case "/path1":
fs = fasthttp.FS{
Root: "/home/test/path1",
IndexNames: []string{"index.html"},
}
case "/path2":
fs = fasthttp.FS{
Root: "/home/test/path2",
IndexNames: []string{"index.html"},
}
}
fsHandler := fs.NewRequestHandler()
fsHandler(ctx)
}
if err := fasthttp.ListenAndServe(":8080", requestHandler); err != nil {
fmt.Println("error in ListenAndServe: %s", err)
}