示例#1
0
文件: db.go 项目: jeff235255/forum
func InitDb() (*mgo.Session, error) {
	env := config.GetEnvValue()

	mongoDBDialInfo := &mgo.DialInfo{
		Addrs:    []string{env.Database.Host},
		Timeout:  60 * time.Second,
		Database: env.Database.Name,
		Username: env.Database.User,
		Password: env.Database.Password,
	}
	if mongoSession != nil {
		panic("mongodb is connected!")
	}
	var err error
	if mongoSession, err = mgo.DialWithInfo(mongoDBDialInfo); err != nil {
		return mongoSession, err
	}
	dataBase = env.Database.Name
	return mongoSession, Index()
}
示例#2
0
func Start() error {
	app := setup()
	env := config.GetEnvValue()
	return app.Run(env.Server.Host + ":" + strconv.Itoa(env.Server.Port))
}