-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (29 loc) · 931 Bytes
/
main.go
File metadata and controls
35 lines (29 loc) · 931 Bytes
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
package main
import (
"./controllers"
"github.com/julienschmidt/httprouter"
"gopkg.in/mgo.v2"
"log"
"net/http"
)
func main() {
apiCollection := getSession().DB("cache").C("api")
cacheCollection := getSession().DB("cache").C("cache")
apiController := controllers.NewApiController(apiCollection)
cacheController := controllers.NewCacheController(apiCollection, cacheCollection)
router := httprouter.New()
router.GET("/api", apiController.GetApi)
router.GET("/api/:apikey", cacheController.GetAll)
router.GET("/api/:apikey/:key", cacheController.GetOne)
router.POST("/api/:apikey/:key", cacheController.Create)
router.PUT("/api/:apikey/:key", cacheController.Update)
router.DELETE("/api/:apikey/:key", cacheController.Delete)
log.Fatal(http.ListenAndServe(":8080", router))
}
func getSession() *mgo.Session {
s, err := mgo.Dial("mongodb://mongo.projectmgr2015.tk")
if err != nil {
panic(err)
}
return s
}