2 changed files with 41 additions and 32 deletions
@ -0,0 +1,36 @@ |
|||||||
|
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) |
||||||
|
} |
||||||
Loading…
Reference in new issue