minimal register&login working

This commit is contained in:
arnaucube
2019-06-13 20:26:05 +02:00
parent f7a5bbb91e
commit 0cd29328b4
17 changed files with 348 additions and 16 deletions

30
database/database.go Normal file
View 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
}