mirror of
https://github.com/arnaucube/gogame.git
synced 2026-02-07 03:26:39 +01:00
initial structure
This commit is contained in:
30
db/db.go
Normal file
30
db/db.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package database
|
||||
|
||||
import mgo "gopkg.in/mgo.v2"
|
||||
|
||||
type Db struct {
|
||||
Users *mgo.Collection
|
||||
Planets *mgo.Collection
|
||||
Galaxies *mgo.Collection
|
||||
}
|
||||
|
||||
func New(url string, databaseName string) (*Db, error) {
|
||||
session, err := mgo.Dial("mongodb://" + url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//defer session.Close()
|
||||
|
||||
// Optional. Switch the session to a monotonic behavior.
|
||||
session.SetMode(mgo.Monotonic, true)
|
||||
|
||||
// Optional. Switch the session to a monotonic behavior.
|
||||
session.SetMode(mgo.Monotonic, true)
|
||||
|
||||
db := Db{}
|
||||
db.Users = session.DB(databaseName).C("users")
|
||||
db.Planets = session.DB(databaseName).C("planets")
|
||||
db.Galaxies = session.DB(databaseName).C("galaxies")
|
||||
|
||||
return &db, nil
|
||||
}
|
||||
Reference in New Issue
Block a user