youp0m/see.go

45 lines
1.0 KiB
Go

package main
import (
"html"
"log"
"net/http"
"strings"
)
func SeeRouting(w http.ResponseWriter, r *http.Request) {
log.Printf("Handling request %s: %s\n", r.Method, r.URL.Path)
// Extract URL arguments
var sURL = strings.Split(r.URL.Path, "/")
if sURL[len(sURL)-1] == "" && len(sURL) > 2 {
// Remove trailing /
sURL = sURL[:len(sURL)-1]
}
if len(sURL) < 3 {
http.Error(w, "Please provide a valid hash", http.StatusForbidden)
} else {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(`<!DOCTYPE html>
<html>
<head>
<title>OhSnap</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="/static/css/style.css">
</head>
<body>
<figure class="big">
<img src="/images/` + html.EscapeString("1") + `.jpg" alt="` + html.EscapeString("name") + `">`))
if "name" != "" {
w.Write([]byte(`<figcaption>` + html.EscapeString("name") + `</figcaption>`))
}
w.Write([]byte(` </figure>
</body>
</html>
`))
}
}