summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2026-01-16 21:45:10 +0200
committerMarin Ivanov <[email protected]>2026-01-16 21:45:10 +0200
commit56b97bd9bec99aaad3eb19881ee01fe426428231 (patch)
treef4944c00970fd099050f82996b510c712d178c35 /main.go
parent3ba762877dd49ba47d2ac37c8a2341f4e2ec7b1f (diff)
show results page after submit
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/main.go b/main.go
index c4bf010..75406bc 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
+ "html/template"
"io"
"log"
"net/http"
@@ -33,9 +34,11 @@ type Metadata struct {
ContentType string `json:"contentType"`
}
-//go:embed form.html
+//go:embed form.html result.html
var static embed.FS
+var tmpl = template.Must(template.ParseFS(static, "*.html"))
+
func detectMimetype(input io.Reader) (mimeType string, fileext string, recycled io.Reader, err error) {
header := bytes.NewBuffer(nil)
mtype, err := mimetype.DetectReader(io.TeeReader(input, header))
@@ -154,8 +157,14 @@ func (s *Server) formPost(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("Created posting: %s", name)
- w.Header().Add("location", fmt.Sprintf("%s/%s\n", s.host, name))
- w.WriteHeader(http.StatusFound)
+
+ link := fmt.Sprintf("%s/%s\n", s.host, name)
+ tmplData := map[string]string{
+ "Link": link,
+ }
+ if err := tmpl.ExecuteTemplate(w, "result.html", tmplData); err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ }
}
func (s *Server) servePosting(w http.ResponseWriter, r *http.Request, name string) {
@@ -234,8 +243,7 @@ func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
w.Header().Add("content-type", "text/html; charset=UTF-8")
- f, _ := static.Open("form.html")
- if _, err := io.Copy(w, f); err != nil {
+ if err := tmpl.ExecuteTemplate(w, "form.html", nil); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
} else {