- Improved error handling in various modules for better stability and responsiveness. - Optimized code in several files for improved efficiency and readability. - Enhanced user experience by providing more detailed error responses in the controller. - Strengthened security by ignoring sensitive files in `.gitignore`.
30 lines
525 B
Go
30 lines
525 B
Go
package common
|
|
|
|
import (
|
|
"embed"
|
|
"github.com/gin-contrib/static"
|
|
"io/fs"
|
|
"net/http"
|
|
)
|
|
|
|
// Credit: https://github.com/gin-contrib/static/issues/19
|
|
|
|
type embedFileSystem struct {
|
|
http.FileSystem
|
|
}
|
|
|
|
func (e embedFileSystem) Exists(prefix string, path string) bool {
|
|
_, err := e.Open(path)
|
|
return err == nil
|
|
}
|
|
|
|
func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem {
|
|
efs, err := fs.Sub(fsEmbed, targetPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return embedFileSystem{
|
|
FileSystem: http.FS(efs),
|
|
}
|
|
}
|