summaryrefslogtreecommitdiffstats
path: root/modules/public/static.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/public/static.go')
-rw-r--r--modules/public/static.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/public/static.go b/modules/public/static.go
index 3e8865c3f9..76050632c9 100644
--- a/modules/public/static.go
+++ b/modules/public/static.go
@@ -7,6 +7,8 @@
package public
import (
+ "io/ioutil"
+
"gitea.com/macaron/macaron"
)
@@ -17,3 +19,34 @@ func Static(opts *Options) macaron.Handler {
// used when in the options there is no FileSystem.
return opts.staticHandler("")
}
+
+func Asset(name string) ([]byte, error) {
+ f, err := Assets.Open("/" + name)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ return ioutil.ReadAll(f)
+}
+
+func AssetNames() []string {
+ realFS := Assets.(vfsgen۰FS)
+ var results = make([]string, 0, len(realFS))
+ for k := range realFS {
+ results = append(results, k[1:])
+ }
+ return results
+}
+
+func AssetIsDir(name string) (bool, error) {
+ if f, err := Assets.Open("/" + name); err != nil {
+ return false, err
+ } else {
+ defer f.Close()
+ if fi, err := f.Stat(); err != nil {
+ return false, err
+ } else {
+ return fi.IsDir(), nil
+ }
+ }
+}