-
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.
Answered by
aldas
Nov 6, 2024
Replies: 1 comment 1 reply
-
You might want to read golang/go#61232 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
maxim0r
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might want to read golang/go#61232