bundle.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2019-2023 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. // +build bundle
  16. package bundle
  17. import (
  18. "embed"
  19. "fmt"
  20. "io/fs"
  21. "net/http"
  22. "github.com/drakkan/sftpgo/v2/internal/version"
  23. )
  24. func init() {
  25. version.AddFeature("+bundle")
  26. }
  27. //go:embed templates/*
  28. var templatesFs embed.FS
  29. //go:embed static/*
  30. var staticFs embed.FS
  31. //go:embed openapi/*
  32. var openapiFs embed.FS
  33. // GetTemplatesFs returns the embedded filesystem with the SFTPGo templates
  34. func GetTemplatesFs() embed.FS {
  35. return templatesFs
  36. }
  37. // GetStaticFs return the http Filesystem with the embedded static files
  38. func GetStaticFs() http.FileSystem {
  39. fsys, err := fs.Sub(staticFs, "static")
  40. if err != nil {
  41. err = fmt.Errorf("unable to get embedded filesystem for static files: %w", err)
  42. panic(err)
  43. }
  44. return http.FS(fsys)
  45. }
  46. // GetOpenAPIFs return the http Filesystem with the embedded static files
  47. func GetOpenAPIFs() http.FileSystem {
  48. fsys, err := fs.Sub(openapiFs, "openapi")
  49. if err != nil {
  50. err = fmt.Errorf("unable to get embedded filesystem for OpenAPI files: %w", err)
  51. panic(err)
  52. }
  53. return http.FS(fsys)
  54. }