Correct asset file name
This commit is contained in:
parent
e80d2fca4d
commit
b6973eddb0
22
main.go
22
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -36,6 +37,11 @@ type Response struct {
|
||||||
DELKEY string `json:"delkey"`
|
DELKEY string `json:"delkey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
Title string
|
||||||
|
Body []byte
|
||||||
|
}
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -166,12 +172,14 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/xml")
|
w.Header().Set("Content-Type", "application/xml")
|
||||||
w.Write(x)
|
w.Write(x)
|
||||||
|
|
||||||
case "html":
|
case "html":
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
io.WriteString(w, "<p><b>URL</b>: <a href='"+b.URL+"'>"+b.URL+"</a></p>")
|
io.WriteString(w, "<p><b>URL</b>: <a href='"+b.URL+"'>"+b.URL+"</a></p>")
|
||||||
io.WriteString(w, "<p><b>Delete Key</b>: <a href='"+ADDRESS+"/del/"+b.ID+"/"+b.DELKEY+"'>"+b.DELKEY+"</a></p>")
|
io.WriteString(w, "<p><b>Delete Key</b>: <a href='"+ADDRESS+"/del/"+b.ID+"/"+b.DELKEY+"'>"+b.DELKEY+"</a></p>")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
w.Header().Set("Content-Type", "plain/text")
|
||||||
io.WriteString(w, b.URL+"\n")
|
io.WriteString(w, b.URL+"\n")
|
||||||
io.WriteString(w, "delete key: "+b.DELKEY+"\n")
|
io.WriteString(w, "delete key: "+b.DELKEY+"\n")
|
||||||
}
|
}
|
||||||
|
@ -209,7 +217,21 @@ func getPaste(paste string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var templates = template.Must(template.ParseFiles("assets/paste.html"))
|
||||||
|
|
||||||
func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
func pasteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
paste := vars["pasteId"]
|
||||||
|
s := getPaste(paste)
|
||||||
|
p := &Page{
|
||||||
|
Title: paste,
|
||||||
|
Body: []byte(s),
|
||||||
|
}
|
||||||
|
err := templates.ExecuteTemplate(w, "assets/paste.html", p)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
func rawHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
Loading…
Reference in New Issue