forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (32 loc) · 935 Bytes
/
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
package main
import "github.com/kataras/iris/v12"
// $ go get -u github.com/go-bindata/go-bindata/...
// $ go-bindata -fs ./data/...
// $ go run .
var page = struct {
Title string
}{"Welcome"}
func newApp() *iris.Application {
app := iris.New()
// Using the iris.PrefixDir you can select
// which directories to use under a particular file system,
// e.g. for views the ./data/views and for static files
// the ./data/public.
templatesFS := iris.PrefixDir("./data/views", AssetFile())
app.RegisterView(iris.HTML(templatesFS, ".html"))
publicFS := iris.PrefixDir("./data/public", AssetFile())
app.HandleDir("/", publicFS)
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Page", page)
ctx.View("index.html")
})
return app
}
func main() {
app := newApp()
// http://localhost:8080
// http://localhost:8080/app.js
// http://localhost:8080/css/main.css
// http://localhost:8080/app2
app.Listen(":8080")
}