This commit is contained in:
leah 2022-01-29 15:18:22 +00:00
parent e7a522fba7
commit 725ef46e45
1 changed files with 9 additions and 6 deletions

15
main.go
View File

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