1
0

embed.go 660 B

12345678910111213141516171819202122232425262728293031323334
  1. //go:build !unembed
  2. package middleware
  3. import (
  4. "path"
  5. "github.com/0xJacky/Nginx-UI/app"
  6. "github.com/gin-contrib/static"
  7. "github.com/gin-gonic/gin"
  8. "github.com/spf13/afero"
  9. "github.com/uozi-tech/cosy/logger"
  10. )
  11. func mustFs(dir string) (serverFileSystem static.ServeFileSystem) {
  12. fs, err := app.GetDistFS()
  13. if err != nil {
  14. logger.Error(err)
  15. return
  16. }
  17. // Create a sub filesystem for the dist directory
  18. subFS := afero.NewBasePathFs(fs, path.Join("dist", dir))
  19. httpSubFS := afero.NewHttpFs(subFS)
  20. serverFileSystem = ServerFileSystemType{
  21. httpSubFS,
  22. }
  23. return
  24. }
  25. func ServeStatic() gin.HandlerFunc {
  26. return static.Serve("/", mustFs(""))
  27. }