-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (39 loc) · 1.28 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
package main
import (
"github.com/go-siris/siris"
"github.com/go-siris/siris/context"
"github.com/go-siris/siris/view"
)
// $ go get -u github.com/jteeuwen/go-bindata/...
// $ go-bindata ./public/...
// $ go build
// $ ./embedding-single-page-application
var page = struct {
Title string
}{"Welcome"}
func newApp() *siris.Application {
app := siris.New()
app.AttachView(view.HTML("./public", ".html").Binary(Asset, AssetNames))
app.Get("/", func(ctx context.Context) {
ctx.ViewData("Page", page)
ctx.View("index.html")
})
assetHandler := app.StaticEmbeddedHandler("./public", Asset, AssetNames)
app.SPA(assetHandler)
return app
}
func main() {
app := newApp()
// http://localhost:8080
// http://localhost:8080/index.html
// http://localhost:8080/app.js
// http://localhost:8080/css/main.css
app.Run(siris.Addr(":8080"))
}
// Note that app.Use/UseGlobal/Done will be executed
// only to the registered routes like our index (app.Get("/", ..)).
// The file server is clean, but you can still add middleware to that by wrapping its "assetHandler".
//
// With this method, unlike StaticWeb("/" , "./public") which is not working by-design anymore,
// all custom http errors and all routes are working fine with a file server that is registered
// to the root path of the server.