Skip to content

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

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

Closed
magicodex opened this issue Oct 24, 2024 · 1 comment · Fixed by #59
Closed

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

magicodex opened this issue Oct 24, 2024 · 1 comment · Fixed by #59

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
}
@appleboy
Copy link
Member

appleboy commented Apr 7, 2025

I will take it.

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

Successfully merging a pull request may close this issue.

2 participants