1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-26 22:37:08 +00:00

Full support of the http.FileSystem on all view engines as requested at #1575

Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-05 08:34:09 +03:00
parent 7e6d453dad
commit e1f25eb098
50 changed files with 1613 additions and 1226 deletions

View File

@@ -5,7 +5,9 @@ import (
)
// Follow these steps first:
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -prefix "assets" -fs ./assets/...
// $ go run .
// "physical" files are not used, you can delete the "assets" folder and run the example.

View File

@@ -6,7 +6,9 @@ import (
// How to run:
//
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -prefix "../embedding-files-into-app/assets/" -fs ../embedding-files-into-app/assets/...
// $ go run .
// Time to complete the compression and caching of [2/3] files: 31.9998ms

View File

@@ -7,7 +7,9 @@ import (
)
// How to run:
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -nomemcopy -fs -prefix "../http2push/assets" ../http2push/assets/...
// # OR if the ./assets directory was inside this example foder:
// # go-bindata -nomemcopy -refix "assets" ./assets/...

View File

@@ -2,7 +2,9 @@ package main
import "github.com/kataras/iris/v12"
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .

View File

@@ -20,8 +20,8 @@ import (
"time"
)
func bindataRead(data, name string) ([]byte, error) {
gz, err := gzip.NewReader(strings.NewReader(data))
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("read %q: %v", name, err)
}
@@ -168,82 +168,82 @@ func AssetFile() http.FileSystem {
return &assetOperator{}
}
var _publicAppJs = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2a\xcf\xcc\x4b\xc9\x2f\xd7\x4b\xcc\x49\x2d\x2a\xd1\x50\x4a\x2c\x28\xd0\xcb\x2a\x56\xc8\xc9\x4f\x4c\x49\x4d\x51\x48\x2b\xca\xcf\x55\x88\x51\xd2\x57\xd2\xb4\x06\x04\x00\x00\xff\xff\xa9\x06\xf7\xa3\x27\x00\x00\x00"
var _appJs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2a\xcf\xcc\x4b\xc9\x2f\xd7\x4b\xcc\x49\x2d\x2a\xd1\x50\x4a\x2c\x28\xd0\xcb\x2a\x56\xc8\xc9\x4f\x4c\x49\x4d\x51\x48\x2b\xca\xcf\x55\x88\x51\xd2\x57\xd2\xb4\x06\x04\x00\x00\xff\xff\xa9\x06\xf7\xa3\x27\x00\x00\x00")
func publicAppJsBytes() ([]byte, error) {
func appJsBytes() ([]byte, error) {
return bindataRead(
_publicAppJs,
"public/app.js",
_appJs,
"app.js",
)
}
func publicAppJs() (*asset, error) {
bytes, err := publicAppJsBytes()
func appJs() (*asset, error) {
bytes, err := appJsBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "public/app.js", size: 39, mode: os.FileMode(438), modTime: time.Unix(1595516291, 0)}
info := bindataFileInfo{name: "app.js", size: 39, mode: os.FileMode(438), modTime: time.Unix(1599156854, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _publicApp2IndexHtml = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x34\x8d\x41\x0a\xc2\x40\x0c\x45\xf7\x81\xdc\xe1\x9f\xc0\xd0\xae\x43\xc0\x9d\xd7\xa8\x4c\x24\x85\xd4\x09\x32\x0b\xbd\xbd\xb4\xd6\xe5\x87\xf7\xde\xd7\x18\x5b\x1a\x13\x93\x86\x2f\xcd\x98\x00\x40\xc7\x3a\xd2\xed\x5a\x85\x59\xe5\x37\x98\x54\x4e\x84\x49\xef\xbd\x7d\xfe\x70\x4c\x86\x9b\x67\x76\x3c\x5e\x7d\xc3\x52\x35\xcb\xfa\x6c\xfe\xbe\xec\x71\xa8\xc4\x74\xd8\xa7\x73\x84\xf6\xd7\x6f\x00\x00\x00\xff\xff\xfd\x28\x92\x95\x7c\x00\x00\x00"
var _app2IndexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x34\x8d\x41\x0a\xc2\x40\x0c\x45\xf7\x81\xdc\xe1\x9f\xc0\xd0\xae\x43\xc0\x9d\xd7\xa8\x4c\x24\x85\xd4\x09\x32\x0b\xbd\xbd\xb4\xd6\xe5\x87\xf7\xde\xd7\x18\x5b\x1a\x13\x93\x86\x2f\xcd\x98\x00\x40\xc7\x3a\xd2\xed\x5a\x85\x59\xe5\x37\x98\x54\x4e\x84\x49\xef\xbd\x7d\xfe\x70\x4c\x86\x9b\x67\x76\x3c\x5e\x7d\xc3\x52\x35\xcb\xfa\x6c\xfe\xbe\xec\x71\xa8\xc4\x74\xd8\xa7\x73\x84\xf6\xd7\x6f\x00\x00\x00\xff\xff\xfd\x28\x92\x95\x7c\x00\x00\x00")
func publicApp2IndexHtmlBytes() ([]byte, error) {
func app2IndexHtmlBytes() ([]byte, error) {
return bindataRead(
_publicApp2IndexHtml,
"public/app2/index.html",
_app2IndexHtml,
"app2/index.html",
)
}
func publicApp2IndexHtml() (*asset, error) {
bytes, err := publicApp2IndexHtmlBytes()
func app2IndexHtml() (*asset, error) {
bytes, err := app2IndexHtmlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "public/app2/index.html", size: 124, mode: os.FileMode(438), modTime: time.Unix(1572105320, 0)}
info := bindataFileInfo{name: "app2/index.html", size: 124, mode: os.FileMode(438), modTime: time.Unix(1599156854, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _publicCssMainCss = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4a\xca\x4f\xa9\x54\xa8\xe6\xe5\x52\x50\x50\x50\x48\x4a\x4c\xce\x4e\x2f\xca\x2f\xcd\x4b\xd1\x4d\xce\xcf\xc9\x2f\xb2\x52\x48\xca\x49\x4c\xce\xb6\xe6\xe5\xaa\xe5\xe5\x02\x04\x00\x00\xff\xff\x03\x25\x9c\x89\x29\x00\x00\x00"
var _cssMainCss = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4a\xca\x4f\xa9\x54\xa8\xe6\xe5\x52\x50\x50\x50\x48\x4a\x4c\xce\x4e\x2f\xca\x2f\xcd\x4b\xd1\x4d\xce\xcf\xc9\x2f\xb2\x52\x48\xca\x49\x4c\xce\xb6\xe6\xe5\xaa\xe5\xe5\x02\x04\x00\x00\xff\xff\x03\x25\x9c\x89\x29\x00\x00\x00")
func publicCssMainCssBytes() ([]byte, error) {
func cssMainCssBytes() ([]byte, error) {
return bindataRead(
_publicCssMainCss,
"public/css/main.css",
_cssMainCss,
"css/main.css",
)
}
func publicCssMainCss() (*asset, error) {
bytes, err := publicCssMainCssBytes()
func cssMainCss() (*asset, error) {
bytes, err := cssMainCssBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "public/css/main.css", size: 41, mode: os.FileMode(438), modTime: time.Unix(1565946441, 0)}
info := bindataFileInfo{name: "css/main.css", size: 41, mode: os.FileMode(438), modTime: time.Unix(1599156854, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _publicIndexHtml = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x34\x8e\x41\x0e\xc2\x20\x10\x45\xf7\x24\xdc\xe1\xa7\x07\x80\x74\x3f\xb2\x76\xe9\xc2\x0b\x60\x41\xc1\x50\x21\xc0\x42\xd3\xf4\xee\x06\x4a\x97\x93\xf7\x66\xde\x90\xab\x6b\x50\x9c\x71\x46\xce\x6a\xa3\x38\x03\x00\xaa\xbe\x06\xab\xb6\x0d\xe2\xa6\x5f\x56\xdc\xdb\x88\x7d\x27\x79\x00\xce\x48\x0e\x9d\x33\x7a\x44\xf3\x3b\x17\xdd\xac\x70\xb5\x21\x44\x3c\x73\x5c\xe1\x3f\xc6\x7e\x45\x6b\x80\xa4\x9b\xbb\x3f\xcc\xb2\x64\x9f\x2a\x4a\x5e\x2e\x93\xd4\x29\x89\x77\x99\x14\x40\xf2\x00\xbd\x31\x2e\xf7\x5c\xfb\xf3\x1f\x00\x00\xff\xff\x25\xe9\x37\x57\xae\x00\x00\x00"
var _indexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x34\x8e\x41\x0e\xc2\x20\x10\x45\xf7\x24\xdc\xe1\xa7\x07\x80\x74\x3f\xb2\x76\xe9\xc2\x0b\x60\x41\xc1\x50\x21\xc0\x42\xd3\xf4\xee\x06\x4a\x97\x93\xf7\x66\xde\x90\xab\x6b\x50\x9c\x71\x46\xce\x6a\xa3\x38\x03\x00\xaa\xbe\x06\xab\xb6\x0d\xe2\xa6\x5f\x56\xdc\xdb\x88\x7d\x27\x79\x00\xce\x48\x0e\x9d\x33\x7a\x44\xf3\x3b\x17\xdd\xac\x70\xb5\x21\x44\x3c\x73\x5c\xe1\x3f\xc6\x7e\x45\x6b\x80\xa4\x9b\xbb\x3f\xcc\xb2\x64\x9f\x2a\x4a\x5e\x2e\x93\xd4\x29\x89\x77\x99\x14\x40\xf2\x00\xbd\x31\x2e\xf7\x5c\xfb\xf3\x1f\x00\x00\xff\xff\x25\xe9\x37\x57\xae\x00\x00\x00")
func publicIndexHtmlBytes() ([]byte, error) {
func indexHtmlBytes() ([]byte, error) {
return bindataRead(
_publicIndexHtml,
"public/index.html",
_indexHtml,
"index.html",
)
}
func publicIndexHtml() (*asset, error) {
bytes, err := publicIndexHtmlBytes()
func indexHtml() (*asset, error) {
bytes, err := indexHtmlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "public/index.html", size: 174, mode: os.FileMode(438), modTime: time.Unix(1565946441, 0)}
info := bindataFileInfo{name: "index.html", size: 174, mode: os.FileMode(438), modTime: time.Unix(1599156854, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -300,10 +300,10 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
"public/app.js": publicAppJs,
"public/app2/index.html": publicApp2IndexHtml,
"public/css/main.css": publicCssMainCss,
"public/index.html": publicIndexHtml,
"app.js": appJs,
"app2/index.html": app2IndexHtml,
"css/main.css": cssMainCss,
"index.html": indexHtml,
}
// AssetDir returns the file names below a certain
@@ -347,16 +347,14 @@ type bintree struct {
}
var _bintree = &bintree{nil, map[string]*bintree{
"public": {nil, map[string]*bintree{
"app.js": {publicAppJs, map[string]*bintree{}},
"app2": {nil, map[string]*bintree{
"index.html": {publicApp2IndexHtml, map[string]*bintree{}},
}},
"css": {nil, map[string]*bintree{
"main.css": {publicCssMainCss, map[string]*bintree{}},
}},
"index.html": {publicIndexHtml, map[string]*bintree{}},
"app.js": {appJs, map[string]*bintree{}},
"app2": {nil, map[string]*bintree{
"index.html": {app2IndexHtml, map[string]*bintree{}},
}},
"css": {nil, map[string]*bintree{
"main.css": {cssMainCss, map[string]*bintree{}},
}},
"index.html": {indexHtml, map[string]*bintree{}},
}}
// RestoreAsset restores an asset under the given directory

View File

@@ -4,8 +4,10 @@ import (
"github.com/kataras/iris/v12"
)
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go-bindata -nomemcopy -fs ./public/...
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .
var page = struct {
@@ -14,20 +16,16 @@ var page = struct {
func newApp() *iris.Application {
app := iris.New()
app.RegisterView(iris.HTML("./public", ".html").Binary(Asset, AssetNames))
app.RegisterView(iris.HTML(AssetFile(), ".html"))
app.HandleDir("/", AssetFile())
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Page", page)
ctx.View("index.html")
})
// We didn't add a `-prefix "public"` argument on go-bindata command
// because the view's `Assset` and `AssetNames` require fullpath.
// Make use of the `PrefixDir` to serve assets on cases like that;
// when bindata.go file contains files that are
// not necessary public assets to be served.
app.HandleDir("/", iris.PrefixDir("public", AssetFile()))
return app
}