Compare commits

..

No commits in common. "994d7054bb80ab5a3fabcb06ce55f6566ccc7f12" and "2d84849f3e7b848eba23d39aee86c1c861a3aa42" have entirely different histories.

2 changed files with 5 additions and 43 deletions

31
main.go
View file

@ -2,7 +2,6 @@ package main
import (
"fmt"
"html/template"
"io"
"log"
"net/http"
@ -11,42 +10,20 @@ import (
var currentConfig config
type pasteView struct {
Content string
Key string
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
clearPath := strings.ReplaceAll(r.URL.Path, "/raw", "")
db := connectDB()
path := strings.ReplaceAll(r.URL.Path, "/raw", "")
switch r.Method {
case "GET":
if path == "/" {
http.ServeFile(w, r, "./static/index.html")
} else if strings.HasPrefix(path, "/static/") {
fs := http.FileServer(http.Dir("./static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
} else {
if urlExist(clearPath) {
if strings.HasSuffix(path, "/raw") {
pasteContent := db.HGet(ctx, clearPath, "content").Val()
_, err := io.WriteString(w, pasteContent)
if urlExist(path) {
_, err := io.WriteString(w, "This plak exists")
if err != nil {
log.Println(err)
}
} else {
pasteContent := db.HGet(ctx, path, "content").Val()
s := pasteView{Content: pasteContent, Key: strings.TrimPrefix(path, "/")}
t, err := template.ParseFiles("templates/paste.html")
if err != nil {
log.Println(err)
}
err = t.Execute(w, s)
if err != nil {
log.Println(err)
}
return
}
} else {
w.WriteHeader(http.StatusNotFound)

View file

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{.Key}}</title>
<meta charset="UTF-8">
<meta content="width=device-width, user-scalable=no, initial-scale=1.0"
name="viewport">
<meta content="ie=edge" http-equiv="X-UA-Compatible">
<title>Plak {{.Key}}• Plakken</title>
<link href="/static/style.css" rel="stylesheet">
</head>
<body>
<pre><code>{{.Content}}</code></pre>
</body>
</html>