You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

static.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // +build bindata
  2. // Copyright 2016 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package options
  6. import (
  7. "fmt"
  8. "io/ioutil"
  9. "path"
  10. "code.gitea.io/gitea/modules/setting"
  11. "github.com/Unknwon/com"
  12. )
  13. var (
  14. directories = make(directorySet)
  15. )
  16. // Dir returns all files from bindata or custom directory.
  17. func Dir(name string) ([]string, error) {
  18. if directories.Filled(name) {
  19. return directories.Get(name), nil
  20. }
  21. var (
  22. result []string
  23. )
  24. customDir := path.Join(setting.CustomPath, "options", name)
  25. if com.IsDir(customDir) {
  26. files, err := com.StatDir(customDir, true)
  27. if err != nil {
  28. return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
  29. }
  30. result = append(result, files...)
  31. }
  32. files, err := AssetDir(path.Join("..", "..", "options", name))
  33. if err != nil {
  34. return []string{}, fmt.Errorf("Failed to read embedded directory. %v", err)
  35. }
  36. result = append(result, files...)
  37. return directories.AddAndGet(name, result), nil
  38. }
  39. // Locale reads the content of a specific locale from bindata or custom path.
  40. func Locale(name string) ([]byte, error) {
  41. return fileFromDir(path.Join("locale", name))
  42. }
  43. // Readme reads the content of a specific readme from bindata or custom path.
  44. func Readme(name string) ([]byte, error) {
  45. return fileFromDir(path.Join("readme", name))
  46. }
  47. // Gitignore reads the content of a gitignore locale from bindata or custom path.
  48. func Gitignore(name string) ([]byte, error) {
  49. return fileFromDir(path.Join("gitignore", name))
  50. }
  51. // License reads the content of a specific license from bindata or custom path.
  52. func License(name string) ([]byte, error) {
  53. return fileFromDir(path.Join("license", name))
  54. }
  55. // fileFromDir is a helper to read files from bindata or custom path.
  56. func fileFromDir(name string) ([]byte, error) {
  57. customPath := path.Join(setting.CustomPath, "options", name)
  58. if com.IsFile(customPath) {
  59. return ioutil.ReadFile(customPath)
  60. }
  61. return Asset(name)
  62. }