-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (35 loc) · 1001 Bytes
/
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
package main
import (
"github.com/gorilla/mux"
"html/template"
"log"
"net/http"
"os"
)
func main() {
db, err := ConnectDB("bcc49feaf6f6d4", "74b6ab4e", "us-cdbr-iron-east-03.cleardb.net", "3306", "ad_afa2c365c758c76")
if err != nil {
log.Panic(err)
}
log.Println("Database sucsuessfully connected!")
r := mux.NewRouter()
r.HandleFunc("/ws", websocketHandler)
r.HandleFunc("/get/", db.DBGet()).Methods("GET")
r.HandleFunc("/", indexHandler)
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
http.Handle("/", r)
go updateListen(db)
port := os.Getenv("VCAP_APP_PORT")
if port == "" {
port = "3000"
}
log.Println("http server listening at localhost:" + port)
http.ListenAndServe(":"+port, nil)
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
tmpl, _ := template.ParseFiles("templates/index.html")
tmpl.Execute(w, nil)
}
func handleWebErr(w http.ResponseWriter, err error) {
http.Error(w, "Internal server error: "+err.Error(), 500)
}