Add html output type

This commit is contained in:
Eliot Whalan 2016-06-23 13:45:00 +10:00
parent 5092706792
commit cdf50c04e7
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
2 changed files with 16 additions and 14 deletions

View File

@ -29,7 +29,7 @@
<div class="page-header">
<h1>Pantsu Paste</h1>
</div>
<form action="/save" method="post" class="form-horizontal">
<form action="/save/html" method="post" class="form-horizontal">
<fieldset>
<div class="well">
<div class="form-group is-empty">
@ -451,7 +451,7 @@
</form>
<div class="well">
<code>$ &lt;command&gt; | curl -F 'p=&lt;-' https://p.pantsu.cat/save</code><br/>
<code>https://p.pantsu.cat/save/(XML|JSON)</code><br/>
<code>https://p.pantsu.cat/save/(XML|JSON|HTML)</code><br/>
<code>https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>https://p.pantsu.cat/del/(PASTE)/(DELKEY)</code<br/>
<p>Source: <a href="https://github.com/ewhal/Pastebin">Pastebin</a></p>

26
main.go
View File

@ -19,18 +19,13 @@ import (
)
const (
ADDRESS = "http://localhost:9900"
LENGTH = 6
DELETE = ADDRESS + "/del/{PASTE}/{DELKEY}\n"
PASTEARGS = ADDRESS + "/p/{PASTE}/(python|language)\n"
URLARGS = ADDRESS + "/save/XML|JSON\n"
SOURCE = "Source: https://github.com/ewhal/Pastebin\n"
TEXT = "$ <command> | curl -F 'p=<-' " + ADDRESS + "/save" + "\n" + PASTEARGS + URLARGS + DELETE + SOURCE
PORT = ":9900"
USERNAME = ""
PASS = ""
NAME = ""
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
ADDRESS = "http://localhost:9900"
LENGTH = 6
PORT = ":9900"
USERNAME = ""
PASS = ""
NAME = ""
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
)
type Response struct {
@ -169,6 +164,13 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/xml")
w.Write(x)
case "html":
w.Header().Set("Content-Type", "text/html")
io.WriteString(w, "<p>ID</p><p>"+b.ID+"</p><br/>")
io.WriteString(w, "<p>hash</p><p>"+b.HASH+"</p><br/>")
io.WriteString(w, "<p>URL</p><a href='"+b.URL+"'>"+b.URL+"</a><br/>")
io.WriteString(w, "<p>hash</p><p>"+b.SIZE+"</p><br/>")
io.WriteString(w, "<a href='"+b.URL+"/p/"+b.DELKEY+"'>"+b.DELKEY+"</a>")
default:
io.WriteString(w, b.URL+"\n")