2017-07-30 14:06:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-30 18:14:20 +00:00
|
|
|
"database/sql"
|
2017-07-30 15:20:48 +00:00
|
|
|
"html/template"
|
|
|
|
"log"
|
2017-07-30 14:06:38 +00:00
|
|
|
"net/http"
|
|
|
|
|
2017-07-31 17:37:52 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
|
2017-07-30 14:06:38 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2017-07-30 18:14:20 +00:00
|
|
|
var db *sql.DB
|
|
|
|
|
2017-07-30 14:06:38 +00:00
|
|
|
func init() {
|
2017-07-31 17:37:52 +00:00
|
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
2017-07-30 15:20:48 +00:00
|
|
|
tpl, err := template.ParseGlob("templates/*.html")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2017-07-30 18:14:20 +00:00
|
|
|
db, err = sql.Open("sqlite3", "calibre.db")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2017-07-30 15:20:48 +00:00
|
|
|
app := &bouquins.Bouquins{
|
|
|
|
tpl,
|
2017-07-30 18:14:20 +00:00
|
|
|
db,
|
2017-07-30 15:20:48 +00:00
|
|
|
}
|
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() {
|
2017-07-30 18:14:20 +00:00
|
|
|
defer db.Close()
|
2017-07-30 14:06:38 +00:00
|
|
|
http.ListenAndServe(":9000", nil)
|
|
|
|
}
|