You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
702 B
36 lines
702 B
package main |
|
|
|
import ( |
|
"html/template" |
|
"log" |
|
"net/http" |
|
) |
|
|
|
type App struct { |
|
store TxtStore |
|
} |
|
|
|
func (a *App) mainPageHandler(writer http.ResponseWriter, request *http.Request) { |
|
html, err := template.ParseFS(staticFiles, "static/index.html") |
|
if err != nil { |
|
log.Fatal(err) |
|
} |
|
|
|
guestbook, err := a.store.GetGuestbook() |
|
if err != nil { |
|
log.Fatal(err) |
|
} |
|
|
|
if err := html.Execute(writer, guestbook); err != nil { |
|
log.Fatal(err) |
|
} |
|
} |
|
|
|
func (a *App) newCommentHandler(writer http.ResponseWriter, request *http.Request) { |
|
comment := request.FormValue("comment") |
|
if err := a.store.AddComment(comment); err != nil { |
|
log.Fatal(err) |
|
} |
|
|
|
http.Redirect(writer, request, "/", http.StatusFound) |
|
}
|
|
|