-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
executable file
·66 lines (57 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
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/codegangsta/negroni"
"github.com/ziutek/mymysql/mysql"
_ "github.com/ziutek/mymysql/thrsafe"
)
var dbConn mysql.Conn
func IndexHandler(w http.ResponseWriter, r *http.Request) {
// Set the location header to redirect to admin panel.
w.Write([]byte("Permission Denied"))
// Write the HTTP response code. This has to be written after any required headers are set.
w.WriteHeader(403)
}
func main() {
dbConn = mysql.New("tcp", "", "127.0.0.1:3306", "cron", "1234", "asterisk")
err := dbConn.Connect()
checkErr(err)
go sendLatestJSON()
r := mux.NewRouter()
// Routes consist of a path and a handler function.
r.HandleFunc("/", IndexHandler)
wallboard_base := mux.NewRouter()
r.PathPrefix("/wallboard").Handler(negroni.New(
negroni.NewRecovery(),
negroni.NewLogger(),
&negroni.Static{
Dir: http.Dir("wallboard_html"),
Prefix: "/wallboard",
IndexFile: "index.html",
},
negroni.Wrap(wallboard_base),
))
wallboard_sub := wallboard_base.PathPrefix("/wallboard").Subrouter()
// Wallboard WebSocket Page
wallboard_sub.HandleFunc("/", WallboardPage)
wallboard_sub.HandleFunc("/index.html", WallboardPage)
wallboard_sub.HandleFunc("/wallboard.php", WallboardPage)
// Old style polling interface
wallboard_sub.HandleFunc("/poll.html", WallboardPollPage)
// Edit page.
wallboard_sub.HandleFunc("/edit.html", WallboardEditPage)
wallboard_sub.HandleFunc("/save", WallboardSavePage)
// WebSocket Interface
wallboard_sub.HandleFunc("/status_ws", AgentStatusWS)
// Polling JSON Interface
wallboard_sub.HandleFunc("/status", AgentStatusSingle)
//wallboard_sub.HandleFunc("/wallboard_json.php", AgentStatusSingle)
// Bind to a port and pass our router in
http.ListenAndServe(":8888", r)
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}