Add download button

This commit is contained in:
Eliot Whalan 2016-06-24 12:17:23 +10:00
parent 36675bc4ff
commit ac2eb12dfb
3 changed files with 14 additions and 9 deletions

View File

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

View File

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

21
main.go
View File

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