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 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 public
  6. import (
  7. "io/ioutil"
  8. "gitea.com/macaron/macaron"
  9. )
  10. // Static implements the macaron static handler for serving assets.
  11. func Static(opts *Options) macaron.Handler {
  12. opts.FileSystem = Assets
  13. // we don't need to pass the directory, because the directory var is only
  14. // used when in the options there is no FileSystem.
  15. return opts.staticHandler("")
  16. }
  17. func Asset(name string) ([]byte, error) {
  18. f, err := Assets.Open("/" + name)
  19. if err != nil {
  20. return nil, err
  21. }
  22. defer f.Close()
  23. return ioutil.ReadAll(f)
  24. }
  25. func AssetNames() []string {
  26. realFS := Assets.(vfsgen۰FS)
  27. var results = make([]string, 0, len(realFS))
  28. for k := range realFS {
  29. results = append(results, k[1:])
  30. }
  31. return results
  32. }
  33. func AssetIsDir(name string) (bool, error) {
  34. if f, err := Assets.Open("/" + name); err != nil {
  35. return false, err
  36. } else {
  37. defer f.Close()
  38. if fi, err := f.Stat(); err != nil {
  39. return false, err
  40. } else {
  41. return fi.IsDir(), nil
  42. }
  43. }
  44. }