-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.39 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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
)
type pagedata struct {
Title string
Content interface{}
}
var templates *template.Template
func aboutHandler(w http.ResponseWriter, r *http.Request) {
data := pagedata{"About Me", ""}
templates.ExecuteTemplate(w, "about.html", data)
}
func projectsHandler(w http.ResponseWriter, r *http.Request) {
data := pagedata{"Selected Projects", AllProjects}
templates.ExecuteTemplate(w, "projects.html", data)
}
func stackHandler(w http.ResponseWriter, r *http.Request) {
data := pagedata{"Tech Stack", Stack}
templates.ExecuteTemplate(w, "stack.html", data)
}
func faviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./favicon.ico")
}
func robotsHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./robots.txt")
}
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "2820"
}
fs := http.FileServer(http.Dir("static"))
templates = template.Must(template.ParseGlob("templates/*.html"))
mux := http.NewServeMux()
mux.Handle("/static/", http.StripPrefix("/static/", fs))
mux.HandleFunc("/", aboutHandler)
mux.HandleFunc("/projects", projectsHandler)
mux.HandleFunc("/stack", stackHandler)
mux.HandleFunc("/favicon.ico", faviconHandler)
mux.HandleFunc("/robots.txt", robotsHandler)
fmt.Printf("Listening on %v\n", port)
log.Fatal(http.ListenAndServe(":"+port, mux))
}