revmgo

package module
Version: v0.0.0-...-0457aa1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2013 License: MIT Imports: 3 Imported by: 3

README

revmgo

mgo module for revel framework

Module Use

app.conf

Add the following line to your app.conf.

module.revmgo = github.com/hermanschaaf/revmgo

Additional settings can be configured via the following directives

revmgo.dial

Please review the documentation at mgo.Session.Dial() for information on the syntax and valid settings.

revmgo.method

This can be one of 'clone', 'copy', 'new'. See mgo.Session.New() for more information.

init.go

Then in your init.go include the following

revel.OnAppStart(revmgo.AppInit)
Adding the interceptors

You will also need to add the interceptors in a init.go file within the controllers directory:

package controllers

import "github.com/hermanschaaf/revmgo"

func init() {
    revmgo.ControllerInit()
}
Embedding the controller

In any controller you want to have mongo connectivity you must include the MongoController.

Add the following import line in source files that will embed MongoController.

 "github.com/hermanschaaf/revmgo"

Embed the MongoController on your custom controller;

type Application struct {
	*revel.Controller
  revmgo.MongoController
	// Other fields
}

Your controller will now have a MongoSession variable of type *mgo.Session. Use this to query your mongo datastore.

See Also

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Session  *mgo.Session // Global mgo Session
	Dial     string       // http://godoc.org/labix.org/v2/mgo#Dial
	Method   string       // clone, copy, new http://godoc.org/labix.org/v2/mgo#Session.New
	Database string       // (optional) database name to connect to
)

Functions

func AppInit

func AppInit()

func ControllerInit

func ControllerInit()

func MethodError

func MethodError(m string) error

Types

type MongoController

type MongoController struct {
	*revel.Controller
	MongoSession *mgo.Session  // named MongoSession to avoid collision with revel.Session
	Database     *mgo.Database // shortcut to the database you want to connect to by default
}

func (*MongoController) Begin

func (c *MongoController) Begin() revel.Result

Connect to mgo if we haven't already and return a copy/new/clone of the session and database connection

func (*MongoController) End

func (c *MongoController) End() revel.Result

Close the controller session if we have an active one.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL