2017-06-15 19:02:08 +02:00
|
|
|
package main
|
|
|
|
|
2022-09-25 23:34:18 +02:00
|
|
|
import (
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/x/errors"
|
|
|
|
)
|
2017-06-15 19:02:08 +02:00
|
|
|
|
2022-07-19 21:48:04 +02:00
|
|
|
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
2022-09-25 23:34:18 +02:00
|
|
|
// $ go-bindata -prefix "data" -fs ./data/...
|
2019-10-25 00:04:08 +02:00
|
|
|
// $ go run .
|
2017-06-15 19:02:08 +02:00
|
|
|
|
|
|
|
var page = struct {
|
|
|
|
Title string
|
|
|
|
}{"Welcome"}
|
|
|
|
|
|
|
|
func newApp() *iris.Application {
|
|
|
|
app := iris.New()
|
2020-09-05 07:34:09 +02:00
|
|
|
|
2022-09-25 23:34:18 +02:00
|
|
|
app.RegisterView(iris.HTML(AssetFile(), ".html").RootDir("views"))
|
|
|
|
|
2020-09-14 17:36:04 +02:00
|
|
|
// Using the iris.PrefixDir you can select
|
|
|
|
// which directories to use under a particular file system,
|
2022-09-25 23:34:18 +02:00
|
|
|
// e.g. for views the ./public:
|
|
|
|
// publicFS := iris.PrefixDir("./public", AssetFile())
|
|
|
|
publicFS := iris.PrefixDir("./public", AssetFile())
|
2020-09-14 17:36:04 +02:00
|
|
|
app.HandleDir("/", publicFS)
|
2017-06-15 19:02:08 +02:00
|
|
|
|
2017-08-27 19:35:23 +02:00
|
|
|
app.Get("/", func(ctx iris.Context) {
|
2017-06-15 19:02:08 +02:00
|
|
|
ctx.ViewData("Page", page)
|
2022-09-25 23:34:18 +02:00
|
|
|
if err := ctx.View("index.html"); err != nil {
|
|
|
|
errors.InvalidArgument.Err(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
2017-06-15 19:02:08 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := newApp()
|
|
|
|
|
|
|
|
// http://localhost:8080
|
|
|
|
// http://localhost:8080/app.js
|
|
|
|
// http://localhost:8080/css/main.css
|
2019-10-25 00:04:08 +02:00
|
|
|
// http://localhost:8080/app2
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2017-06-15 19:02:08 +02:00
|
|
|
}
|