summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go18
-rw-r--r--result.html78
2 files changed, 91 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 {
diff --git a/result.html b/result.html
new file mode 100644
index 0000000..2c52d23
--- /dev/null
+++ b/result.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Gloginki</title>
+
+ <style>
+ :root {
+ --bg: #f6f8fa;
+ --card-bg: #ffffff;
+ --border: #d0d7de;
+ --text: #24292f;
+ --muted: #57606a;
+ --primary: #2da44e;
+ --primary-hover: #2c974b;
+ --danger: #cf222e;
+ --radius: 6px;
+ }
+
+ * {
+ box-sizing: border-box;
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
+ Helvetica, Arial, sans-serif;
+ }
+
+ body {
+ margin: 0;
+ padding: 2rem;
+ background: var(--bg);
+ color: var(--text);
+ }
+
+ h1 {
+ margin-bottom: 1rem;
+ font-size: 1.6rem;
+ }
+
+ .container {
+ max-width: 900px;
+ margin: 0 auto;
+ }
+ form {
+ background: var(--card-bg);
+ border: 1px solid var(--border);
+ border-radius: var(--radius);
+ padding: 1.5rem;
+ margin-bottom: 2rem;
+ }
+
+ fieldset {
+ border: 1px solid var(--border);
+ border-radius: var(--radius);
+ padding: 1rem;
+ margin-bottom: 1.2rem;
+ }
+
+ legend {
+ padding: 0 0.5rem;
+ color: var(--muted);
+ font-size: 0.9rem;
+ }
+ </style>
+</head>
+
+<body>
+ <div class="container">
+ <h1>Bin-ки и глогинки.</h1>
+
+ <form>
+ <fieldset>
+ <legend>Link</legend>
+ <a href="{{ .Link }}">{{ .Link }}</a>
+ </fieldset>
+ </form>
+ </div>
+</body>
+</html>