You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
611B

  1. package main
  2. import (
  3. "html/template"
  4. "net/http"
  5. "path/filepath"
  6. "github.com/goanywhere/rex"
  7. "github.com/goanywhere/rex/livereload"
  8. )
  9. type User struct {
  10. Username string
  11. }
  12. func Index(w http.ResponseWriter, r *http.Request) {
  13. if html, err := template.ParseFiles(filepath.Join("views", "index.html")); err != nil {
  14. http.Error(w, err.Error(), http.StatusInternalServerError)
  15. } else {
  16. w.Header().Set("Content-Type", "text/html")
  17. var user = User{Username: rex.Env.String("USER", "guest")}
  18. html.Execute(w, user)
  19. }
  20. }
  21. func main() {
  22. rex.Use(livereload.Middleware)
  23. rex.Get("/", Index)
  24. rex.Run()
  25. }