bundle.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2019 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. //go:build bundle
  15. package bundle
  16. import (
  17. "embed"
  18. "fmt"
  19. "io/fs"
  20. "net/http"
  21. "github.com/drakkan/sftpgo/v2/internal/version"
  22. )
  23. func init() {
  24. version.AddFeature("+bundle")
  25. }
  26. //go:embed templates/*
  27. var templatesFs embed.FS
  28. //go:embed static/*
  29. var staticFs embed.FS
  30. //go:embed openapi/*
  31. var openapiFs embed.FS
  32. // GetTemplatesFs returns the embedded filesystem with the SFTPGo templates
  33. func GetTemplatesFs() embed.FS {
  34. return templatesFs
  35. }
  36. // GetStaticFs return the http Filesystem with the embedded static files
  37. func GetStaticFs() http.FileSystem {
  38. fsys, err := fs.Sub(staticFs, "static")
  39. if err != nil {
  40. err = fmt.Errorf("unable to get embedded filesystem for static files: %w", err)
  41. panic(err)
  42. }
  43. return http.FS(fsys)
  44. }
  45. // GetOpenAPIFs return the http Filesystem with the embedded static files
  46. func GetOpenAPIFs() http.FileSystem {
  47. fsys, err := fs.Sub(openapiFs, "openapi")
  48. if err != nil {
  49. err = fmt.Errorf("unable to get embedded filesystem for OpenAPI files: %w", err)
  50. panic(err)
  51. }
  52. return http.FS(fsys)
  53. }