20 lines
254 B
Go
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")}
|
|
}
|