forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (57 loc) · 1.85 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import "github.com/kataras/iris/v12"
// $ go get -u github.com/go-bindata/go-bindata/...
// $ go-bindata ./public/...
// $ go build
// $ ./embedded-single-page-application-with-other-routes
func newApp() *iris.Application {
app := iris.New()
app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) {
ctx.Writef("404 not found here")
})
app.HandleDir("/", "./public", iris.DirOptions{
Asset: Asset,
AssetInfo: AssetInfo,
AssetNames: AssetNames,
// IndexName: "index.html", // default.
// If you want to show a list of embedded files when inside a directory without an index file:
// ShowList: true,
// DirList: func(ctx iris.Context, dirName string, f http.File) error {
// // [Optional, custom code to show the html list].
// }
})
// Note:
// if you want a dynamic index page then see the file-server/embedded-single-page-application
// which is registering a view engine based on bindata as well and a root route.
app.Get("/ping", func(ctx iris.Context) {
ctx.WriteString("pong")
})
app.Get("/.well-known", func(ctx iris.Context) {
ctx.WriteString("well-known")
})
app.Get(".well-known/ready", func(ctx iris.Context) {
ctx.WriteString("ready")
})
app.Get(".well-known/live", func(ctx iris.Context) {
ctx.WriteString("live")
})
app.Get(".well-known/metrics", func(ctx iris.Context) {
ctx.Writef("metrics")
})
return app
}
func main() {
app := newApp()
// http://localhost:8080/index.html
// http://localhost:8080/app.js
// http://localhost:8080/css/main.css
//
// http://localhost:8080/ping
// http://localhost:8080/.well-known
// http://localhost:8080/.well-known/ready
// http://localhost:8080/.well-known/live
// http://localhost:8080/.well-known/metrics
//
// Remember: we could use the root wildcard `app.Get("/{param:path}")` and serve the files manually as well.
app.Run(iris.Addr(":8080"))
}