-
Notifications
You must be signed in to change notification settings - Fork 20
/
http_index.go
71 lines (60 loc) · 1.81 KB
/
http_index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/espebra/filebin2/ds"
"net/http"
"time"
)
func (h *HTTP) Index(w http.ResponseWriter, r *http.Request) {
type Data struct {
Bin ds.Bin `json:"bin"`
}
var data Data
bin := &ds.Bin{}
bin.Expiration = time.Now().UTC().Add(h.expirationDuration)
err := h.dao.Bin().Insert(bin)
if err != nil {
fmt.Printf("Unable to insert new bin: %s\n", err.Error())
http.Error(w, "Errno 301", http.StatusInternalServerError)
return
}
data.Bin = *bin
if err := h.templates.ExecuteTemplate(w, "index", data); err != nil {
fmt.Printf("Failed to execute template: %s\n", err.Error())
http.Error(w, "Errno 302", http.StatusInternalServerError)
return
}
}
func (h *HTTP) About(w http.ResponseWriter, r *http.Request) {
//w.Header().Set("Cache-Control", "max-age=900")
if err := h.templates.ExecuteTemplate(w, "about", nil); err != nil {
fmt.Printf("Failed to execute template: %s\n", err.Error())
http.Error(w, "Errno 302", http.StatusInternalServerError)
return
}
}
func (h *HTTP) API(w http.ResponseWriter, r *http.Request) {
type Data struct {
Bin ds.Bin `json:"bin"`
}
var data Data
//w.Header().Set("Cache-Control", "max-age=900")
if err := h.templates.ExecuteTemplate(w, "api", data); err != nil {
fmt.Printf("Failed to execute template: %s\n", err.Error())
http.Error(w, "Errno 302", http.StatusInternalServerError)
return
}
}
func (h *HTTP) APISpec(w http.ResponseWriter, r *http.Request) {
type Data struct {
Bin ds.Bin `json:"bin"`
}
var data Data
w.Header().Set("Content-Type", "application/json")
//w.Header().Set("Cache-Control", "max-age=900")
if err := h.templates.ExecuteTemplate(w, "apispec", data); err != nil {
fmt.Printf("Failed to execute template: %s\n", err.Error())
http.Error(w, "Errno 302", http.StatusInternalServerError)
return
}
}