/
server.go
28 lines (22 loc) · 917 Bytes
/
server.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
package main
import (
"os"
"github.com/jessemillar/rytsar-server/accessors"
"github.com/jessemillar/rytsar-server/controllers"
"github.com/zenazn/goji"
)
func main() {
// Construct the dsn used for the database
dsn := os.Getenv("RYTSAR_DB_USER") + ":" + os.Getenv("RYTSAR_DB_PASS") + "@tcp(" + os.Getenv("RYTSAR_DB_HOST") + ":" + os.Getenv("RYTSAR_DB_PORT") + ")/" + os.Getenv("RYTSAR_DB_NAME")
// Construct a new AccessorGroup and connects it to the database
ag := new(accessors.AccessorGroup)
ag.ConnectToDB("mysql", dsn)
// Constructs a new ControllerGroup and gives it the AccessorGroup
cg := new(controllers.ControllerGroup)
cg.Accessors = ag
goji.Get("/health", cg.Health) // Service health
goji.Get("/database/:latitude/:longitude/:radius", cg.DumpDatabase)
goji.Get("/count/:latitude/:longitude/:radius", cg.CountNearbyEnemies)
goji.Delete("/delete/:id", cg.DeleteEnemy)
goji.Serve()
}