Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method "embedFileSystem.Exists " does not use parameter "prefix" #57

Open
magicodex opened this issue Oct 24, 2024 · 0 comments
Open

Method "embedFileSystem.Exists " does not use parameter "prefix" #57

magicodex opened this issue Oct 24, 2024 · 0 comments

Comments

@magicodex
Copy link

When I use embed.FS and the static resource url prefix is ​​"/demo/", the static resource cannot be found.
Here is my code:

import (
  "embed"
  "github.com/gin-gonic/gin"
  "github.com/gin-contrib/static"
)

var embedFS embed.FS
engine := gin.Default()

staticFS := static.EmbedFolder(embedFS , "public)
staticHandlerFunc := static.Serve("/demo/", staticFS )
engine.Use(staticHandlerFunc)

The problem lies in this method( file "embed_folder.go"):

func (e embedFileSystem) Exists(prefix string, path string) bool {
  _, err := e.Open(path)
  return err == nil
}

This is the code I changed and everything is working fine:

func (e embedFileSystem) Exists(prefix string, path string) bool {
  if prefix != "" {
    path = strings.TrimPrefix(path, prefix)
  }

  _, err := e.Open(path)
  return err == nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant