示例#1
0
func TestMain(m *testing.M) {
	// db
	dbString := os.Getenv("BBSGO_DB_TEST")
	if dbString == "" {
		dbString = "root:@tcp(localhost:3306)/bbs_go_test?parseTime=true&loc=Local"
	}
	db, err := bbsmysql.NewMySqlDb(dbString)
	if err != nil {
		panic(err)
	}

	// log
	logLevel := os.Getenv("BBSGO_LOG_LEVEL")
	if logLevel == "" {
		logLevel = "debug"
	}
	err = log.Init(log.Conf{LogLevel: logLevel})
	if err != nil {
		panic(err)
	}

	dbMap = model.Init(db, log.Logger)
	userDao = UserImpl{dbm: dbMap, dbs: dbMap}
	threadDao = ThreadImpl{dbm: dbMap, dbs: dbMap}

	os.Exit(m.Run())
}
示例#2
0
func main() {
	conf := parseConf()
	parseLogger(conf.LogFile, conf.LogLevel)
	dbm := parseDb(conf.DbMaster)
	dbs := parseDb(conf.DbSlave)
	dbMMap := model.Init(dbm, log.Logger)
	dbSMap := model.Init(dbs, log.Logger)

	mux := goji.NewMux()
	userDao := dao.NewUser(dbMMap, dbSMap)
	threadDao := dao.NewThread(dbMMap, dbSMap)
	threadService := service.NewThread(userDao, threadDao)
	threadHandler := handler.NewThread(threadService)
	mux.HandleFuncC(pat.Get("/v1/threads"), wrap(threadHandler.List))
	log.Logger.Info("starting server...")
	http.ListenAndServe("localhost:8080", mux)
}