resources_embedded.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2019-2022 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 util
  17. import (
  18. "html/template"
  19. "github.com/drakkan/sftpgo/v2/internal/bundle"
  20. "github.com/drakkan/sftpgo/v2/internal/logger"
  21. )
  22. // FindSharedDataPath searches for the specified directory name in searchDir
  23. // and in system-wide shared data directories.
  24. // If name is an absolute path it is returned unmodified.
  25. func FindSharedDataPath(name, _ string) string {
  26. return name
  27. }
  28. // LoadTemplate parses the given template paths.
  29. // It behaves like template.Must but it writes a log before exiting.
  30. // You can optionally provide a base template (e.g. to define some custom functions)
  31. func LoadTemplate(base *template.Template, paths ...string) *template.Template {
  32. var t *template.Template
  33. var err error
  34. templateFs := bundle.GetTemplatesFs()
  35. if base != nil {
  36. base, err = base.Clone()
  37. if err == nil {
  38. t, err = base.ParseFS(templateFs, paths...)
  39. }
  40. } else {
  41. t, err = template.ParseFS(templateFs, paths...)
  42. }
  43. if err != nil {
  44. logger.ErrorToConsole("error loading required template: %v", err)
  45. logger.Error(logSender, "", "error loading required template: %v", err)
  46. panic(err)
  47. }
  48. return t
  49. }