forked from electricdusk/rushlink
Put index in template
This commit is contained in:
parent
675245722f
commit
8803281285
2
go.mod
2
go.mod
@ -5,8 +5,6 @@ go 1.12
|
||||
require (
|
||||
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/prometheus/client_golang v1.1.0
|
||||
go.etcd.io/bbolt v1.3.3
|
||||
|
14
handlers.go
14
handlers.go
@ -2,7 +2,7 @@ package main
|
||||
|
||||
//go:generate go get github.com/go-bindata/go-bindata
|
||||
//go:generate go get -u github.com/go-bindata/go-bindata/...
|
||||
//go:generate go-bindata -pkg $GOPACKAGE assets/
|
||||
//go:generate go-bindata -pkg $GOPACKAGE text/
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
@ -56,7 +57,8 @@ var base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345
|
||||
var base64Encoder = base64.NewEncoding(base64Alphabet).WithPadding(base64.NoPadding)
|
||||
|
||||
// Page contents
|
||||
var indexContents = MustAsset("assets/index.txt")
|
||||
var baseTemplate = template.New("empty")
|
||||
var indexTemplate = template.Must(baseTemplate.Parse(string(MustAsset("text/index.txt"))))
|
||||
|
||||
func (t PasteType) String() (string, error) {
|
||||
switch t {
|
||||
@ -81,8 +83,7 @@ func (t PasteState) String() (string, error) {
|
||||
}
|
||||
|
||||
func indexGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := w.Write(indexContents)
|
||||
if err != nil {
|
||||
if err := indexTemplate.Execute(w, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@ -245,7 +246,10 @@ func shortenPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
saveURL, err := r.URL.Parse(string(storedPaste.Key))
|
||||
if err != nil {
|
||||
log.Printf("error: %v\n", errors.Wrap(err, "parsing url"))
|
||||
err = errors.Wrap(err, "parsing url")
|
||||
log.Printf("error: %v\n", err)
|
||||
fmt.Fprintf(w, "internal server error: %v\n", err)
|
||||
return
|
||||
}
|
||||
var base64OwnerToken = make([]byte, 24)
|
||||
base64Encoder.Encode(base64OwnerToken, storedPaste.OwnerToken[:])
|
||||
|
Loading…
Reference in New Issue
Block a user