2021-02-13 08:39:05 -08:00
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"html/template"
|
|
|
|
|
|
|
|
//"github.com/gorilla/sessions"
|
|
|
|
|
|
|
|
//"github.com/zorchenhimer/hacker-quotes/models"
|
|
|
|
//"github.com/zorchenhimer/hacker-quotes/database"
|
2021-02-13 08:52:59 -08:00
|
|
|
"github.com/zorchenhimer/hacker-quotes"
|
2021-02-13 08:39:05 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Frontend struct {
|
|
|
|
//db database.DB
|
2021-02-13 08:52:59 -08:00
|
|
|
hq hacker.HackerQuotes
|
2021-02-13 08:39:05 -08:00
|
|
|
//cookies *sessions.CookieStore
|
|
|
|
templates map[string]*template.Template
|
|
|
|
}
|
|
|
|
|
2021-02-13 08:52:59 -08:00
|
|
|
func New(hq hacker.HackerQuotes) (*Frontend, error) {
|
2021-02-13 08:39:05 -08:00
|
|
|
f := &Frontend{
|
2021-02-13 08:52:59 -08:00
|
|
|
hq: hq,
|
2021-02-13 08:39:05 -08:00
|
|
|
//cookies: sessions.NewCookieStore([]byte("some auth key"), []byte("some encrypt key")),
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Frontend) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
//parts := strings.Split(r.URL.Path, "/")
|
|
|
|
switch r.URL.Path {
|
|
|
|
case "/":
|
|
|
|
f.home(w, r)
|
|
|
|
|
|
|
|
//case "/admin":
|
|
|
|
// f.admin(w, r)
|
|
|
|
|
|
|
|
default:
|
|
|
|
f.notFound(w, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Frontend) notFound(w http.ResponseWriter, r *http.Request) {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
}
|