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

isogoapp.go 956B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. "github.com/gorilla/mux"
  7. "github.com/isomorphicgo/isogoapp/common"
  8. "github.com/isomorphicgo/isogoapp/handlers"
  9. "github.com/isomorphicgo/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.HandleFunc("/js/client.js", isokit.GopherjsScriptHandler)
  24. r.HandleFunc("/js/client.js.map", isokit.GopherjsScriptMapHandler)
  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. }