kauri
2 years ago
1 changed files with 0 additions and 55 deletions
@ -1,55 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"html/template" |
||||
"net/http" |
||||
) |
||||
|
||||
var page *template.Template |
||||
|
||||
func main() { |
||||
fmt.Println("welcome to forum") |
||||
|
||||
page = template.Must(template.ParseGlob("templates/*.html")) |
||||
|
||||
http.Handle("/styles/", http.StripPrefix("/styles/", http.FileServer(http.Dir("styles")))) |
||||
|
||||
http.HandleFunc("/", IndexHandler) |
||||
http.HandleFunc("/profile/", ProfileHandler) |
||||
http.HandleFunc("/register/", LoginHandler) |
||||
http.HandleFunc("/signin/", LoginHandler) |
||||
|
||||
http.HandleFunc("/profile/posts/", LoginHandler) // css not reached
|
||||
http.HandleFunc("/profile/likes/", LoginHandler) // css not reached
|
||||
|
||||
http.HandleFunc("/posts/", ErrHandler) // temporary
|
||||
http.HandleFunc("/categories/", ErrHandler) // temporary
|
||||
|
||||
fmt.Println("http://localhost:8080") |
||||
http.ListenAndServe(":8080", nil) |
||||
} |
||||
|
||||
func IndexHandler(w http.ResponseWriter, r *http.Request) { |
||||
if err := page.ExecuteTemplate(w, "home.html", nil); err != nil { |
||||
http.Error(w, "Internal Error", http.StatusInternalServerError) |
||||
} |
||||
} |
||||
|
||||
func ProfileHandler(w http.ResponseWriter, r *http.Request) { |
||||
if err := page.ExecuteTemplate(w, "profile.html", nil); err != nil { |
||||
http.Error(w, "Internal Error", http.StatusInternalServerError) |
||||
} |
||||
} |
||||
|
||||
func LoginHandler(w http.ResponseWriter, r *http.Request) { |
||||
if err := page.ExecuteTemplate(w, "login.html", nil); err != nil { |
||||
http.Error(w, "Internal Error", http.StatusInternalServerError) |
||||
} |
||||
} |
||||
|
||||
func ErrHandler(w http.ResponseWriter, r *http.Request) { |
||||
if err := page.ExecuteTemplate(w, "error.html", nil); err != nil { |
||||
http.Error(w, "Internal Error", http.StatusInternalServerError) |
||||
} |
||||
} |
Loading…
Reference in new issue