-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.go
55 lines (45 loc) · 1.15 KB
/
app.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
package main
import (
"log"
"net/http"
"os"
"html/template"
//for extracting service credentials from VCAP_SERVICES
//"github.com/cloudfoundry-community/go-cfenv"
)
const (
DEFAULT_PORT = "8080"
)
var index = template.Must(template.ParseFiles(
"templates/_base.html",
"templates/index.html",
))
var converter = template.Must(template.ParseFiles(
"templates/_base.html",
"templates/us2sane.html",
))
var messagegen = template.Must(template.ParseFiles(
"templates/_base.html",
"templates/motd.html",
))
func helloworld(w http.ResponseWriter, req *http.Request) {
index.Execute(w, nil)
}
func us2sane(w http.ResponseWriter, req *http.Request) {
converter.Execute(w, nil)
}
func motd(w http.ResponseWriter, req *http.Request) {
messagegen.Execute(w, nil)
}
func main() {
var port string
if port = os.Getenv("PORT"); len(port) == 0 {
port = DEFAULT_PORT
}
http.HandleFunc("/", helloworld)
http.HandleFunc("/converter", us2sane)
http.HandleFunc("/motd", motd)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
log.Printf("Starting app on port %+v\n", port)
http.ListenAndServe(":"+port, nil)
}