whoops
This commit is contained in:
parent
e7a522fba7
commit
725ef46e45
15
main.go
15
main.go
|
@ -147,7 +147,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||
validpath := regexp.MustCompile(`^/(signup|login|hello)$`)
|
||||
m := validpath.FindStringSubmatch(path)
|
||||
|
||||
if m == nil {
|
||||
if m != nil {
|
||||
userid, err := r.Cookie("user-id")
|
||||
if errors.As(err, &http.ErrNoCookie) {
|
||||
http.Redirect(w, r, "/hello", http.StatusFound)
|
||||
|
@ -157,6 +157,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
switch path {
|
||||
case "/":
|
||||
tmpl = "templates/home.html"
|
||||
t, _ := template.ParseFiles(tmpl)
|
||||
t.Execute(w, config)
|
||||
default:
|
||||
|
||||
exists, err := exists(loc)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -166,10 +171,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
tmpl = "templates/home.html"
|
||||
t, _ := template.ParseFiles(tmpl)
|
||||
t.Execute(w, config)
|
||||
default:
|
||||
|
||||
tmpl = fmt.Sprintf("templates%s.html", path)
|
||||
t, _ := template.ParseFiles(tmpl)
|
||||
t.Execute(w, config)
|
||||
|
@ -177,7 +179,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func loginHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// userid, err := r.Cookie("user-id")
|
||||
userid, err := r.Cookie("user-id")
|
||||
fmt.Print(userid, err)
|
||||
// if err != nil {
|
||||
// useridbody := uuid.New()
|
||||
// expiration := time.Now().Add(365 * 24 * time.Hour)
|
||||
|
|
Reference in New Issue