revmgo

package module
v0.0.0-...-6654c73 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2015 License: MIT Imports: 5 Imported by: 26

README

revmgo

I have stopped all work on revel as I don't think it is a good solution in Go.

Please follow the fork here #18; https://github.com/janekolszak/revmgo

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

)
View Source
var ObjectIdBinder = revel.Binder{

	Bind: revel.ValueBinder(func(val string, typ reflect.Type) reflect.Value {
		if len(val) == 0 {
			return reflect.Zero(typ)
		}
		if bson.IsObjectIdHex(val) {
			objId := bson.ObjectIdHex(val)
			return reflect.ValueOf(objId)
		} else {
			revel.ERROR.Print("ObjectIdBinder.Bind - invalid ObjectId!")
			return reflect.Zero(typ)
		}
	}),

	Unbind: func(output map[string]string, name string, val interface{}) {
		var hexStr string
		hexStr = fmt.Sprintf("%s", val.(bson.ObjectId).Hex())

		if bson.IsObjectIdHex(hexStr) {
			output[name] = hexStr
		} else {
			revel.ERROR.Print("ObjectIdBinder.Unbind - invalid ObjectId!")
			output[name] = ""
		}
	},
}

Custom TypeBinder for bson.ObjectId Makes additional Id parameters in actions obsolete

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
}

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

func (*MongoController) End

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

Close the controller session if we have an active one.

Directories

Path Synopsis
testapp
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL