-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
52 lines (46 loc) · 1.55 KB
/
app.go
File metadata and controls
52 lines (46 loc) · 1.55 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
43
44
45
46
47
48
49
50
51
52
package main
import (
"code.google.com/p/go.net/websocket"
"github.com/nickdirienzo/go-json-rest"
"labix.org/v2/mgo"
"log"
"net/http"
)
type Api struct {
DbName string
MongoSession *mgo.Session
}
func StartWebSocketServer() {
http.Handle("/ws", websocket.Handler(wsHandler))
hostname, port := "127.0.0.1", "8081"
log.Println("Starting WS Server on " + hostname + ":" + port)
err := http.ListenAndServe(hostname+":"+port, nil)
if err != nil {
log.Fatal("Could not start WS server:", err.Error())
}
}
func main() {
session, err := mgo.Dial("localhost")
if err != nil {
log.Fatal("Could not get Mongo")
}
api := Api{MongoSession: session, DbName: "mugo"}
handler := rest.ResourceHandler{}
handler.SetRoutes(
rest.RouteObjectMethod("GET", "/sessions", &api, "GetSessions"),
rest.RouteObjectMethod("POST", "/songs", &api, "PostSongs"),
rest.RouteObjectMethod("GET", "/songs", &api, "GetSongs"),
rest.RouteObjectMethod("GET", "/map", &api, "GMapsMirror"),
rest.RouteObjectMethod("GET", "/mockPins", &api, "GenerateMockPins"),
rest.RouteObjectMethod("GET", "/login", &api, "LogIn"),
rest.RouteObjectMethod("GET", "/rdio", &api, "RdioCallback"),
rest.RouteObjectMethod("GET", "/playbackToken", &api, "GetPlaybackToken"),
rest.RouteObjectMethod("GET", "/search", &api, "SearchRdio"),
rest.RouteObjectMethod("GET", "/allSongs", &api, "GetAllSongs"),
)
go h.run()
go StartWebSocketServer()
hostname, port := "127.0.0.1", "8080"
log.Println("Starting server on " + hostname + ":" + port)
http.ListenAndServe(hostname+":"+port, &handler)
}