add(backend): paste view
This commit is contained in:
parent
b240a5669b
commit
46c866df5a
1 changed files with 17 additions and 5 deletions
20
main.go
20
main.go
|
@ -11,19 +11,31 @@ import (
|
|||
var currentConfig config
|
||||
|
||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
path := strings.ReplaceAll(r.URL.Path, "/raw", "")
|
||||
path := r.URL.Path
|
||||
clearPath := strings.ReplaceAll(r.URL.Path, "/raw", "")
|
||||
db := connectDB()
|
||||
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(path) {
|
||||
_, err := io.WriteString(w, "This plak exists")
|
||||
if urlExist(clearPath) {
|
||||
if strings.HasSuffix(path, "/raw") {
|
||||
content := db.HGet(ctx, clearPath, "content").Val()
|
||||
_, err := io.WriteString(w, content)
|
||||
if err != nil {
|
||||
return
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
content := db.HGet(ctx, path, "content").Val()
|
||||
_, err := io.WriteString(w, content)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
|
Loading…
Reference in a new issue