123456789101112131415161718192021222324252627282930313233343536373839 |
- package ui
- import (
- "io"
- "log"
- "net/http"
- "strings"
- )
- const rootInputName = "form[url]"
- // handleGetRoot handles path /
- func handleGetRoot(w http.ResponseWriter, r *http.Request) {
- sess, err := store.Get(r, globals.SessionName)
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- return
- }
- data := struct {
- Flashes []interface{}
- InputName string
- SubmitName string
- }{
- sess.Flashes(),
- rootInputName,
- "submit",
- }
- sess.Save(r, w)
- sw := &strings.Builder{}
- err = tmpl.ExecuteTemplate(sw, "home", data)
- if err != nil {
- log.Println(err)
- w.WriteHeader(http.StatusInternalServerError)
- } else {
- w.WriteHeader(http.StatusOK)
- io.Copy(w, strings.NewReader(sw.String()))
- }
- }
|