Basic app structure

This commit is contained in:
Meutel 2017-07-30 16:06:38 +02:00
parent eaf4b6a239
commit 8685efeb8e
3 changed files with 60 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.swp
*~
go-bouquins

19
bouquins/bouquins.go Normal file
View File

@ -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")
}

40
main.go Normal file
View File

@ -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)
}