有没有什么办法可以使用fasthttp框架来服务多个目录?为了相同的目的,我编写了下面的代码。但是,这段代码并没有像我期望的那样工作。当我访问本地主机:8080/PATH1,它会抛出错误和警告,fasthttp:多个Dir服务器不工作
无法打开请求的路径
2017年10月13日16时57分01秒0.977#0000000100000001 - 127.0。 0.1:8080 < - > 127.0.0.1:48870 - 获取http://localhost:8080/path1 - 无法打开文件 “/家/测试/路径1”: 开 /家/测试/路径1 /路径1: 没有这样的文件或目录
我不知道这个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)
}
可能的重复[Where Go Web服务器查找文件](https://stackoverflow.com/questions/46093251/where-does-go-web-server-look-for-the-files) – Flimzy