go-bouquins/main.go

49 lines
860 B
Go
Raw Normal View History

2017-07-30 14:06:38 +00:00
package main
import (
2017-07-30 15:20:48 +00:00
"html/template"
"log"
2017-07-30 14:06:38 +00:00
"net/http"
"meutel.net/meutel/go-bouquins/bouquins"
)
const (
INDEX = "/"
BOOKS = "/books"
AUTHORS = "/authors"
SERIES = "/series"
JS = "/js/"
CSS = "/css/"
2017-07-30 16:09:27 +00:00
FONTS = "/fonts/"
2017-07-30 14:06:38 +00:00
)
func init() {
2017-07-30 15:20:48 +00:00
tpl, err := template.ParseGlob("templates/*.html")
if err != nil {
log.Fatalln(err)
}
app := &bouquins.Bouquins{
tpl,
}
2017-07-30 14:06:38 +00:00
assets()
router(app)
}
func assets() {
http.Handle(JS, http.FileServer(http.Dir("assets")))
http.Handle(CSS, http.FileServer(http.Dir("assets")))
2017-07-30 16:09:27 +00:00
http.Handle(FONTS, http.FileServer(http.Dir("assets")))
2017-07-30 14:06:38 +00:00
}
func router(app *bouquins.Bouquins) {
http.HandleFunc(INDEX, app.IndexPage)
http.HandleFunc(BOOKS, app.BooksPage)
http.HandleFunc(AUTHORS, app.AuthorsPage)
http.HandleFunc(SERIES, app.SeriesPage)
}
func main() {
http.ListenAndServe(":9000", nil)
}