A basic, barebones web app, intented to be used as a starting point for developing an Isomorphic Go application.

isogoapp.go 969B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. "github.com/gorilla/mux"
  7. "go.isomorphicgo.org/go/isogoapp/common"
  8. "go.isomorphicgo.org/go/isogoapp/handlers"
  9. "go.isomorphicgo.org/go/isokit"
  10. )
  11. var WebAppRoot string = os.Getenv("ISOGO_APP_ROOT")
  12. func main() {
  13. if WebAppRoot == "" {
  14. fmt.Println("The ISOGO_APP_ROOT environment variable must be set before the web server instance can be started.")
  15. os.Exit(1)
  16. }
  17. env := common.Env{}
  18. ts := isokit.NewTemplateSet()
  19. ts.GatherTemplates()
  20. env.TemplateSet = ts
  21. r := mux.NewRouter()
  22. r.HandleFunc("/", handlers.IndexHandler)
  23. r.Handle("/js/client.js", isokit.GopherjsScriptHandler(WebAppRoot))
  24. r.Handle("/js/client.js.map", isokit.GopherjsScriptMapHandler(WebAppRoot))
  25. r.Handle("/template-bundle", handlers.TemplateBundleHandler(&env))
  26. fs := http.FileServer(http.Dir(WebAppRoot + "/static"))
  27. http.Handle("/", r)
  28. http.Handle("/static/", http.StripPrefix("/static", fs))
  29. http.ListenAndServe(":8080", nil)
  30. }