-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (78 loc) · 2.11 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
index, err := ioutil.ReadFile("index.html")
if err != nil {
fmt.Println(err)
}
sindex := string(index)
book, err := ioutil.ReadFile("thebook.html")
if err != nil {
fmt.Println(err)
}
sbook := string(book)
faq, err := ioutil.ReadFile("faq.html")
if err != nil {
fmt.Println(err)
}
sfaq := string(faq)
community, err := ioutil.ReadFile("community.html")
if err != nil {
fmt.Println(err)
}
scommunity := string(community)
terms, err := ioutil.ReadFile("terms.html")
if err != nil {
fmt.Println(err)
}
sterms := string(terms)
privacy, err := ioutil.ReadFile("privacy.html")
if err != nil {
fmt.Println(err)
}
sprivacy := string(privacy)
gettingstarted, err := ioutil.ReadFile("getting_started.html")
if err != nil {
fmt.Println(err)
}
sgettingstarted := string(gettingstarted)
http.HandleFunc("/faq", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sfaq)
})
http.HandleFunc("/community", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, scommunity)
})
http.HandleFunc("/thebook", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sbook)
})
http.HandleFunc("/getting_started", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sgettingstarted)
})
http.HandleFunc("/terms", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sterms)
})
http.HandleFunc("/privacy", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sprivacy)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, sindex)
})
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
go func() {
if err := http.ListenAndServe(":80", http.HandlerFunc(redirectTLS)); err != nil {
fmt.Println("ListenAndServe error: %v", err)
}
}()
err = http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
if err != nil {
fmt.Println(err)
}
}
func redirectTLS(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusMovedPermanently)
}