()
| 5 | ) |
| 6 | |
| 7 | func newApp() *iris.Application { |
| 8 | app := iris.New() |
| 9 | |
| 10 | app.Favicon("./assets/favicon.ico") |
| 11 | |
| 12 | // first parameter is the request path |
| 13 | // second is the system directory |
| 14 | // |
| 15 | // app.HandleDir("/css", iris.Dir("./assets/css")) |
| 16 | // app.HandleDir("/js", iris.Dir("./assets/js")) |
| 17 | |
| 18 | v1 := app.Party("/v1") |
| 19 | v1.HandleDir("/static", iris.Dir("./assets"), iris.DirOptions{ |
| 20 | // Defaults to "/index.html", if request path is ending with **/*/$IndexName |
| 21 | // then it redirects to **/*(/) which another handler is handling it, |
| 22 | // that another handler, called index handler, is auto-registered by the framework |
| 23 | // if end developer does not managed to handle it by hand. |
| 24 | IndexName: "/index.html", |
| 25 | // When files should served under compression. |
| 26 | Compress: false, |
| 27 | // List the files inside the current requested directory if `IndexName` not found. |
| 28 | ShowList: false, |
| 29 | // When ShowList is true you can configure if you want to show or hide hidden files. |
| 30 | ShowHidden: false, |
| 31 | Cache: iris.DirCacheOptions{ |
| 32 | // enable in-memory cache and pre-compress the files. |
| 33 | Enable: true, |
| 34 | // ignore image types (and pdf). |
| 35 | CompressIgnore: iris.MatchImagesAssets, |
| 36 | // do not compress files smaller than size. |
| 37 | CompressMinSize: 300, |
| 38 | // available encodings that will be negotiated with client's needs. |
| 39 | Encodings: []string{"gzip", "br" /* you can also add: deflate, snappy */}, |
| 40 | }, |
| 41 | DirList: iris.DirListRich(), |
| 42 | // If `ShowList` is true then this function will be used instead of the default |
| 43 | // one to show the list of files of a current requested directory(dir). |
| 44 | // DirList: func(ctx iris.Context, dirName string, dir http.File) error { ... } |
| 45 | // |
| 46 | // Optional validator that loops through each requested resource. |
| 47 | // AssetValidator: func(ctx iris.Context, name string) bool { ... } |
| 48 | }) |
| 49 | |
| 50 | // You can also register any index handler manually, order of registration does not matter: |
| 51 | // v1.Get("/static", [...custom middleware...], func(ctx iris.Context) { |
| 52 | // [...custom code...] |
| 53 | // ctx.ServeFile("./assets/index.html") |
| 54 | // }) |
| 55 | |
| 56 | // http://localhost:8080/v1/static |
| 57 | // http://localhost:8080/v1/static/css/main.css |
| 58 | // http://localhost:8080/v1/static/js/jquery-2.1.1.js |
| 59 | // http://localhost:8080/v1/static/favicon.ico |
| 60 | return app |
| 61 | } |
| 62 | |
| 63 | func main() { |
| 64 | app := newApp() |
searching dependent graphs…