MCPcopy Create free account
hub / github.com/kataras/iris / newApp

Function newApp

_examples/file-server/basic/main.go:7–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5)
6
7func 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
63func main() {
64 app := newApp()

Callers 3

TestFileServerBasicFunction · 0.70
TestHandleDirDotFunction · 0.70
mainFunction · 0.70

Calls 4

NewMethod · 0.80
FaviconMethod · 0.65
PartyMethod · 0.65
HandleDirMethod · 0.65

Tested by 2

TestFileServerBasicFunction · 0.56
TestHandleDirDotFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…