mgo module for revel framework
This is a mantained fork of https://github.com/jgraham909/revmgo.
go get github.com/janekolszak/revmgo
revel test github.com/janekolszak/revmgo/testapp dev
In app.conf:
- revmgo.dial = mgo.Session.Dial()
- revmgo.method = One of 'clone', 'copy', 'new'. See mgo.Session.New()
- In app.init() in
app/init.go
add:
revel.OnAppStart(revmgo.AppInit)
- In controllers.init() in
app/controllers/init.go
add
revmgo.ControllerInit()
So a minimal controller's init() would be:
package controllers
import "github.com/janekolszak/revmgo"
func init() {
revmgo.ControllerInit()
}
Embed the MongoController on your custom controller;
package controllers
import (
"github.com/janekolszak/revmgo"
"github.com/revel/revel"
)
type App struct {
*revel.Controller
revmgo.MongoController
// ...
}
The controller will now have a MongoSession variable of type *mgo.Session
. Use this to query your mongo datastore.
Use revmgo in revel.jobs
package controllers
import (
"github.com/janekolszak/revmgo"
"github.com/revel/revel"
)
type Job struct {}
func(j Job){
s, err := revmgo.GetSession()
if err != nil {
// error
}
defer s.Close()
// ...
}
- http://gopkg.in/mgo.v2 for documentation on the mgo driver
- https://github.com/jgraham909/bloggo for a reference implementation (Still a work in progress)