From 044ad65b3e9b6169741e237d4ad04406b4875c13 Mon Sep 17 00:00:00 2001 From: Marin Ivanov Date: Sat, 17 Jan 2026 03:07:06 +0200 Subject: combine result and form into single template --- form.html | 217 ---------------------------------------------------- main.go | 6 +- result.html | 87 --------------------- template.html | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 241 insertions(+), 307 deletions(-) delete mode 100644 form.html delete mode 100644 result.html create mode 100644 template.html diff --git a/form.html b/form.html deleted file mode 100644 index f305eed..0000000 --- a/form.html +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - Gloginki - - - - - -
-

Bin-ки и глогинки.

- -
- -
-
- Text Posting - - -
- -
- File Upload - -
You can also paste an image directly
- -
- -
- Submit -
- -
-
-
- -
-

Image Preview

- -
Paste an image to preview it
-
-
- - - - diff --git a/main.go b/main.go index 24ce456..597726b 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ type Metadata struct { ContentType string `json:"contentType"` } -//go:embed form.html result.html +//go:embed template.html var static embed.FS var tmpl = template.Must(template.ParseFS(static, "*.html")) @@ -218,7 +218,7 @@ func (s *Server) post(w http.ResponseWriter, r *http.Request) { "TextLink": textLink, "FileLink": fileLink, } - if err := tmpl.ExecuteTemplate(w, "result.html", tmplData); err != nil { + if err := tmpl.ExecuteTemplate(w, "template.html", tmplData); err != nil { w.WriteHeader(http.StatusInternalServerError) } } else { @@ -241,7 +241,7 @@ func (s *Server) get(w http.ResponseWriter, r *http.Request) { path := r.URL.Path if path == "/" { w.Header().Add("content-type", "text/html; charset=UTF-8") - if err := tmpl.ExecuteTemplate(w, "form.html", nil); err != nil { + if err := tmpl.ExecuteTemplate(w, "template.html", map[string]any{"Form": true}); err != nil { w.WriteHeader(http.StatusInternalServerError) } } else { diff --git a/result.html b/result.html deleted file mode 100644 index 91c94cf..0000000 --- a/result.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - Gloginki - - - - - -
-

Bin-ки и глогинки.

- -
- {{if .TextLink }} -
- Text Link - {{ .TextLink }} -
- {{end}} - - {{if .FileLink }} -
- File Link - {{ .FileLink }} -
- {{end}} -
-
- - diff --git a/template.html b/template.html new file mode 100644 index 0000000..c780b4b --- /dev/null +++ b/template.html @@ -0,0 +1,238 @@ + + + + + + Gloginki + + + + + +
+

Bin-ки и глогинки.

+ +
+
+ + {{if .Form }} +
+
+ Text Posting + + +
+ +
+ File Upload + +
You can also paste an image directly
+ +
+ +
+ Submit +
+ +
+
+
+ +
+

Image Preview

+ +
Paste an image to preview it
+
+ {{end}} + + {{if .TextLink }} +
+ Text Link + {{ .TextLink }} +
+ {{end}} + + {{if .FileLink }} +
+ File Link + {{ .FileLink }} +
+ {{end}} + +
+
+ + {{if .Form }} + + {{ end }} + + -- cgit v1.2.3