This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
show.go
67 lines (62 loc) · 1.51 KB
/
show.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
// Licensed under GPL, 2016
// Refer to LICENSE for more details
// Refer to README for structural information
package main
import (
"fmt"
"log"
"net/http"
)
func showRegex(w http.ResponseWriter, r *http.Request) {
tx, err := db.Begin()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.ExecuteTemplate(w, "error.gtml", errorPage{
"500 - Internal Server Error",
err.Error(),
})
return
}
var T Task
_, err = fmt.Sscanf(r.RequestURI, "/r/%x", &T.Id)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.ExecuteTemplate(w, "error.gtml", errorPage{
"400 - Bad Request",
"Could not resolve " + r.RequestURI,
})
return
}
if err := tx.Stmt(getone).QueryRow(T.Id).Scan(
&T.Title,
&T.Author,
&T.Discription,
&T.Called,
&T.Created,
); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.ExecuteTemplate(w, "error.gtml", errorPage{
"404 - Not Found",
fmt.Sprintf("Could not find task with the ID %x", T.Id),
})
} else {
T.loadWords(tx)
if err := T.loadSolutions(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.ExecuteTemplate(w, "error.gtml", errorPage{
"500 - Internal Server Error",
err.Error(),
})
return
} else if err := tx.Commit(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.ExecuteTemplate(w, "error.gtml", errorPage{
"500 - Internal Server Error",
err.Error(),
})
return
} else if err := t.ExecuteTemplate(w, "show.gtml", T); err != nil {
log.Println(err)
}
}
}