Add download button

This commit is contained in:
Eliot Whalan 2016-06-24 12:17:23 +10:00
parent 940faf998c
commit e9fe27ea2d
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
3 changed files with 14 additions and 9 deletions

View File

@ -37,6 +37,7 @@
<div class="pull-right">
<div class="row">
<a href="{{.Home}}" class="btn btn-raised btn-primary">Home</a>
<a href="{{.Download}}" class="btn btn-raised btn-primary">Download</a>
<a href="{{.Raw}}" class="btn btn-raised btn-primary">Raw</a>
</div>

View File

@ -37,6 +37,7 @@
<div class="pull-right">
<div class="row">
<a href="%s" class="btn btn-raised btn-primary">Home</a>
<a href="%s" class="btn btn-raised btn-primary">Download</a>
<a href="%s" class="btn btn-raised btn-primary">Raw</a>
</div>

21
main.go
View File

@ -39,10 +39,11 @@ type Response struct {
}
type Page struct {
Title string
Body []byte
Raw string
Home string
Title string
Body []byte
Raw string
Home string
Download string
}
func check(err error) {
@ -235,12 +236,14 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
lang := vars["lang"]
s := getPaste(paste, lang)
link := ADDRESS + "/raw/" + paste
download := ADDRESS + "/download/" + paste
if lang == "" {
p := &Page{
Title: paste,
Body: []byte(s),
Raw: link,
Home: ADDRESS,
Title: paste,
Body: []byte(s),
Raw: link,
Home: ADDRESS,
Download: download,
}
err := templates.ExecuteTemplate(w, "paste.html", p)
if err != nil {
@ -248,7 +251,7 @@ func pasteHandler(w http.ResponseWriter, r *http.Request) {
}
} else {
fmt.Fprintf(w, string(syntax), paste, paste, s, ADDRESS, link)
fmt.Fprintf(w, string(syntax), paste, paste, s, ADDRESS, download, link)
}
}