mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
add support for embed.FS
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
File diff suppressed because one or more lines are too long
@@ -1,21 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
// Follow these steps first:
|
||||
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
||||
// $ go-bindata -prefix "assets" -fs ./assets/...
|
||||
// $ go run .
|
||||
// "physical" files are not used, you can delete the "assets" folder and run the example.
|
||||
//
|
||||
// See `file-server/embedding-gzipped-files-into-app` example as well.
|
||||
//go:embed assets/*
|
||||
var fs embed.FS
|
||||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
app.HandleDir("/static", AssetFile())
|
||||
app.HandleDir("/static", fs)
|
||||
|
||||
/*
|
||||
Or if you need to cache them inside the memory (requires the assets folder
|
||||
|
||||
@@ -40,9 +40,7 @@ func (r resource) strip(strip string) string {
|
||||
}
|
||||
|
||||
func (r resource) loadFromBase(dir string) string {
|
||||
filename := r.String()
|
||||
|
||||
filename = r.strip("/static")
|
||||
filename := r.strip("/static")
|
||||
|
||||
fullpath := filepath.Join(dir, filename)
|
||||
|
||||
@@ -52,11 +50,6 @@ func (r resource) loadFromBase(dir string) string {
|
||||
}
|
||||
|
||||
result := string(b)
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
result = strings.ReplaceAll(result, "\n", "\r\n")
|
||||
result = strings.ReplaceAll(result, "\r\r", "")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user