forked from shivamMg/showcase-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
42 lines (34 loc) · 1.03 KB
/
server.go
File metadata and controls
42 lines (34 loc) · 1.03 KB
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
package main
import (
"net/http"
"text/template"
)
var tmplts = template.Must(template.ParseGlob("templates/*"))
func indexPageHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
projects := getProjects()
err := tmplts.ExecuteTemplate(w, "index", projects)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func aboutPageHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
err := tmplts.ExecuteTemplate(w, "about", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
// For Openshift Deployment
// bind := fmt.Sprintf("%s:%s", os.Getenv("OPENSHIFT_GO_IP"), os.Getenv("OPENSHIFT_GO_PORT"))
// For local testing
bind := ":8080"
http.HandleFunc("/", indexPageHandler)
http.HandleFunc("/about/", aboutPageHandler)
fs := http.FileServer(http.Dir("assets"))
http.Handle("/assets/", http.StripPrefix("/assets/", fs))
http.ListenAndServe(bind, nil)
}