From f97d476b495126fd2474b8e3a2968658395d2a0f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 13 Mar 2024 17:09:48 -0400 Subject: Complete restructure --- handle.go | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 handle.go (limited to 'handle.go') diff --git a/handle.go b/handle.go deleted file mode 100644 index 7414665..0000000 --- a/handle.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "net/http" - "strings" -) - -func (app *application) home(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html; charset=utf-8") - - path := strings.Split(r.URL.Path, "/") - if path[1] != "" { - app.notFound(w) - return - } else { - p, err := app.loadPosts("html/projects", -1) - if err != nil { - app.serverError(w, err) - return - } - - err = renderTemplate(w, "main/index", p) - if err != nil { - app.serverError(w, err) - return - } - } -} - -func (app *application) post(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html; charset=utf-8") - - path := strings.Split(r.URL.Path, "/") - if len(path) > 4 { - app.notFound(w) - } else if len(path) == 4 && path[3] == "" { - http.Redirect(w, r, "/"+path[1]+"/"+path[2], http.StatusFound) - } else { - post, err := app.readFile("html" + strings.TrimSuffix(r.URL.Path, "/") + ".tmpl.html") - if err != nil { - app.notFound(w) - return - } - - var posts []*Post - posts = append(posts, post) - p := &Posts{Contents: posts} - - err = renderTemplate(w, path[1]+"/"+path[2], p) - if err != nil { - app.serverError(w, err) - return - } - } -} -- cgit v1.2.3