resources_embedded.go 1.8 KB

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