func (self *Configuration) Init() error { media.Config.Backend = &Backend{ gridFS: mongo.Database.GridFS(self.GridFSName), images: mongo.NewCollection(self.GridFSName+".images", (*ImageDoc)(nil)), } return nil }
func (self *Configuration) Init() error { if mongo.Database == nil { panic("Package mongo must be initialized before mongomedia") } media.Config.Backend = &backend{ gridFS: mongo.Database.GridFS(self.GridFSName), images: mongo.NewCollection(self.GridFSName+".images", (*ImageDoc)(nil)), } return nil }
// Init must be called after mongo.Init() func Init(name string) error { if name == "" { return errors.New("media.Init() called with empty name") } media.Config.Backend = &Backend{ gridFS: mongo.Database.GridFS(name), images: mongo.NewCollection(name+".images", (*ImageDoc)(nil)), } return nil }
func NewCollection(name string) *mongo.Collection { return mongo.NewCollection(name, modelext.NameDocLabelSelectors...) }
package models import ( "github.com/ungerik/go-start/model" "github.com/ungerik/go-start/mongo" ) var ColorSchemes = mongo.NewCollection("colorschemes") func NewColorScheme() *ColorScheme { return &ColorScheme{ Primary: "blue", Secondary: "black", } } type ColorScheme struct { mongo.DocumentBase `bson:",inline"` Primary model.String Secondary model.String }
func (self *Backend) Init(gridFSName string) { self.GridFS = mongo.Database.GridFS(gridFSName) self.Images = mongo.NewCollection(gridFSName+".images", "Title") self.Blobs = mongo.NewCollection(gridFSName+".blobs", "Title") }
* Time: 3:50 PM * To change this template use File | Settings | File Templates. */ package models import ( "github.com/ungerik/go-start/media" "github.com/ungerik/go-start/model" "github.com/ungerik/go-start/mongo" "github.com/ungerik/go-start/user" ) func init() { } var Users = mongo.NewCollection("projectos") func NewUser() *User { var doc User Users.InitDocument(&doc) return &doc } type User struct { user.User `bson:",inline"` Image media.ImageRef Gender model.Choice `model:"options=,Male,Female"` }