iris/_examples/file-server/single-page-application/embedded-single-page-application/main.go
Gerasimos (Makis) Maropoulos e1f25eb098
Full support of the http.FileSystem on all view engines as requested at #1575
Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
2020-09-05 08:34:09 +03:00

41 lines
757 B
Go

package main
import (
"github.com/kataras/iris/v12"
)
// $ go get -u github.com/go-bindata/go-bindata
// # OR: go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// # to save it to your go.mod file
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .
var page = struct {
Title string
}{"Welcome"}
func newApp() *iris.Application {
app := iris.New()
app.RegisterView(iris.HTML(AssetFile(), ".html"))
app.HandleDir("/", AssetFile())
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")
}