This repository has been archived by the owner on Jul 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdefaultController.go
75 lines (63 loc) · 2.07 KB
/
defaultController.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
72
73
74
75
package main
import (
"html/template"
"net/http"
)
var (
templateMaster string = "html/master.html"
templateIndex string = "html/defaultIndex.html"
templateOrganization string = "html/defaultOrganization.html"
templateContact string = "html/defaultContact.html"
templateThankYou string = "html/defaultThankYou.html"
)
// DefaultIndex renders the default page of the default controller.
func DefaultIndex(w http.ResponseWriter, r *http.Request) {
t := template.Must(template.ParseFiles(
templateMaster,
templateIndex,
))
if err := t.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// DefaultOrganization renders the organization page of the default controller.
func DefaultOrganization(w http.ResponseWriter, r *http.Request) {
t := template.Must(template.ParseFiles(
templateMaster,
templateOrganization,
))
if err := t.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// DefaultContact renders the contact page for the default controller.
func DefaultContact(w http.ResponseWriter, r *http.Request) {
email := r.FormValue("email")
message := r.FormValue("message")
if email == "" || message == "" {
t := template.Must(template.ParseFiles(
templateMaster,
templateContact,
))
if err := t.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
// Use AppEngine to send our thank you cards
from := "TrueTandem LLC <[email protected]>"
subj := "TrueTandem LLC <[email protected]>"
body := "We appreciate your feedback and will get back to you quickly as possible!"
sendEmail(r, from, email, subj, body)
http.Redirect(w, r, "/thank-you", http.StatusSeeOther)
}
}
// DefaultThankYou renders the thank you page after submitting feedback.
func DefaultThankYou(w http.ResponseWriter, r *http.Request) {
t := template.Must(template.ParseFiles(
templateMaster,
templateThankYou,
))
if err := t.Execute(w, nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}