Log:
\n{\"time\":\"2024-11-06T11:34:48.212141+03:00\",\"id\":\"\",\"remote_ip\":\"::1\",\"host\":\"localhost:8080\",\"method\":\"GET\",\"uri\":\"/static_dir/index.html\",\"user_agent\":\"Go-http-client/1.1\",\"status\":200,\"error\":\"\",\"latency\":2067584,\"latency_human\":\"2.067584ms\",\"bytes_in\":0,\"bytes_out\":14}\n{\"time\":\"2024-11-06T11:34:48.212859+03:00\",\"id\":\"\",\"remote_ip\":\"::1\",\"host\":\"localhost:8080\",\"method\":\"GET\",\"uri\":\"/static_zip/index.html\",\"user_agent\":\"Go-http-client/1.1\",\"status\":500,\"error\":\"file does not implement io.ReadSeeker\",\"latency\":106333,\"latency_human\":\"106.333µs\",\"bytes_in\":0,\"bytes_out\":36}\nYou might want to read golang/go#61232
","upvoteCount":1,"url":"https://github.com/labstack/echo/discussions/2696#discussioncomment-11168977"}}}-
|
There is a need to use zip as static resources. But when calling it, the error ‘file does not implement io.ReadSeeker’ occurs. Can you please advise me how to solve the problem? My skill is not enough package main
import (
"archive/zip"
"io/fs"
"net/http"
"os"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
e.Use(middleware.Logger())
// dir
dirFS := os.DirFS("data")
dirFS, _ = fs.Sub(dirFS, "static")
e.StaticFS("/static_dir", dirFS)
// zip
r, err := zip.OpenReader("data.zip")
if err != nil {
panic(err)
}
zipFS, _ := fs.Sub(r, "static")
e.StaticFS("/static_zip", zipFS)
go func() {
if err := e.Start(":8080"); err != nil {
e.StdLogger.Fatal(err)
}
}()
http.Get("http://localhost:8080/static_dir/index.html")
http.Get("http://localhost:8080/static_zip/index.html")
}Log: |
Beta Was this translation helpful? Give feedback.
-
|
You might want to read golang/go#61232 |
Beta Was this translation helpful? Give feedback.
You might want to read golang/go#61232