From 8685efeb8eef4dd5bce73ea74673b3a372f9b118 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 30 Jul 2017 16:06:38 +0200 Subject: [PATCH] Basic app structure --- .gitignore | 1 + bouquins/bouquins.go | 19 +++++++++++++++++++ main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 bouquins/bouquins.go create mode 100644 main.go diff --git a/.gitignore b/.gitignore index 7e2195c..22e9a30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp *~ +go-bouquins diff --git a/bouquins/bouquins.go b/bouquins/bouquins.go new file mode 100644 index 0000000..744a06d --- /dev/null +++ b/bouquins/bouquins.go @@ -0,0 +1,19 @@ +package bouquins + +import "net/http" + +type Bouquins struct { +} + +func (*Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) { + http.Redirect(res, req, "/html/index.html", http.StatusSeeOther) +} +func (*Bouquins) BooksPage(res http.ResponseWriter, req *http.Request) { + panic("not implemented") +} +func (*Bouquins) AuthorsPage(res http.ResponseWriter, req *http.Request) { + panic("not implemented") +} +func (*Bouquins) SeriesPage(res http.ResponseWriter, req *http.Request) { + panic("not implemented") +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..ae2d5a4 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "net/http" + + "meutel.net/meutel/go-bouquins/bouquins" +) + +const ( + INDEX = "/" + BOOKS = "/books" + AUTHORS = "/authors" + SERIES = "/series" + HTML = "/html/" + JS = "/js/" + CSS = "/css/" +) + +func init() { + app := new(bouquins.Bouquins) + assets() + router(app) +} + +func assets() { + http.Handle(HTML, http.FileServer(http.Dir("assets"))) + http.Handle(JS, http.FileServer(http.Dir("assets"))) + http.Handle(CSS, http.FileServer(http.Dir("assets"))) +} + +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) +}