The PrefixDir function
The iris.PrefixDir function wraps an existing "fs" file system and returns a new one which open files by prepending the path with the given "prefix".
1
func PrefixDir(prefix string, fs http.FileSystem) http.FileSystem
Copied!
It is extremely useful when you use a go-bindata file to embed both view templates and public static files. With PrefixDir you can select which directory to use to serve static files and which to render views.

Example

1
│ main.go
2
| bindata.go
3
└───data/
4
└──────views/
5
│ ...your templates
6
└──────public/
7
│ ...your public assets
Copied!
Let's build the bindata.go file which will contain the embedded ./data directory:
1
$ go get -u github.com/go-bindata/go-bindata/...
2
$ go-bindata -fs ./data/...
Copied!
Use the ./data/views for templates and ./data/public for file server:
1
templatesFS := iris.PrefixDir("./data/views", AssetFile())
2
app.RegisterView(iris.HTML(templatesFS, ".html"))
3
4
publicFS := iris.PrefixDir("./data/public", AssetFile())
5
app.HandleDir("/", publicFS)
Copied!
Last modified 1yr ago
Export as PDF
Copy link
Contents
Example