home.go

35 lines
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
package controllers

import (
	"net/http"

	"congo.gg/pkg/application"
)

func Home() (string, *HomeController) {
	return "home", &HomeController{}
}

type HomeController struct {
	application.BaseController
}

func (c *HomeController) Setup(app *application.App) {
	c.BaseController.Setup(app)
	http.Handle("GET /{$}", app.Serve("index.html", nil))
	http.Handle("GET /tutorial", app.Serve("tutorial.html", nil))
	http.Handle("GET /guide", app.Serve("guide.html", nil))
	http.Handle("GET /philosophy", app.Serve("philosophy.html", nil))

	// 404 catch-all (must be registered last, GET only)
	notFound := app.Serve("404.html", nil)
	http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNotFound)
		notFound.ServeHTTP(w, r)
	})
}

func (c HomeController) Handle(r *http.Request) application.Controller {
	c.Request = r
	return &c
}