typeDirOptionsstruct {// Defaults to "/index.html", if request path is ending with **/*/$IndexName// then it redirects to **/*(/).// That index handler is registered automatically// by the framework unless but it can be overriden. IndexName string// PushTargets filenames (map's value) to// be served without additional client's requests (HTTP/2 Push)// when a specific request path (map's key WITHOUT prefix)// is requested and it's not a directory (it's an `IndexFile`).//// Example:// "/": {// "favicon.ico",// "js/main.js",// "css/main.css",// } PushTargets map[string][]string// PushTargetsRegexp like `PushTargets` but accepts regexp which// is compared against all files under a directory (recursively).// The `IndexName` should be set.//// Example:// "/": regexp.MustCompile("((.*).js|(.*).css|(.*).ico)$")// See `iris.MatchCommonAssets` too. PushTargetsRegexp map[string]*regexp.Regexp// Cache to enable in-memory cache and pre-compress files. Cache DirCacheOptions// When files should served under compression. Compress bool// List the files inside the current requested// directory if `IndexName` not found. ShowList bool// If `ShowList` is true then this function will be used instead// of the default one to show the list of files of// a current requested directory(dir).// See `DirListRich` package-level function too. DirList DirListFunc// Files downloaded and saved locally. Attachments Attachments// Optional validator that loops through each requested resource. AssetValidator func(ctx *context.Context, name string) bool}
Quick Start
Let's say that you have an ./assets folder near to your executable and you want the files to be served through http://localhost:8080/static/**/* route.
Now, if you want to embed the static files to be lived inside the executable build in order to not depend on a system directory you can use a tool like go-bindata to convert the files into []byte inside your program. Let's take a quick tutorial on this and how Iris helps to serve those data.
Navigate to your program directory, that the ./assets subdirectory exists and execute:
$go-bindata-fs-prefix"assets"./assets/...
The above creates a generated go file which contains a AssetFile() functions that returns a compatible http.FileSystem you can give to Iris to serve the files.