Is there any way to serve multiple directory using fasthttp framework? I wrote the below code for the same purpose. But, this code is not working as I expected. When I access localhost:8080/path1, It throws error and warnings,
Cannot open requested path
2017/10/13 16:57:01 0.977 #0000000100000001 - 127.0.0.1:8080<->127.0.0.1:48870 - GET http://localhost:8080/path1 - cannot open file "/home/test/path1": open /home/test/path1/path1: no such file or directory
I don't know how this url(/home/test/path1) redirects to (/home/test/path1/path1). What is wrong with the below code ?
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)
}