Skip to content

Latest commit

 

History

History
84 lines (68 loc) · 1.87 KB

README.md

File metadata and controls

84 lines (68 loc) · 1.87 KB

revmgo Build Status

mgo module for revel framework

This is a mantained fork of https://github.com/jgraham909/revmgo.

Installation

    go get github.com/janekolszak/revmgo

Test

    revel test github.com/janekolszak/revmgo/testapp dev

Configuration

In app.conf:

Initialization

  • 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()
    }

Usage

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()
        // ...
    }

See Also