Pracownia.Programowania/common/mongo.go
2018-12-31 15:42:05 +01:00

20 lines
254 B
Go

package common
import (
"gopkg.in/mgo.v2"
)
type mongo struct {
Posts *mgo.Collection
}
var DB *mongo
func ConnectDB() {
session, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
DB = &mongo{Posts: session.DB("blogdb").C("posts")}
}