func main() {
	conf := c.ReadConfig()
	handler := db.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name)
	s.StartAfter(func() (string, bool) {
		return "", handler.Check()
	}, func() {
		log.Printf("connection established....")
	})

	log.Println("Starting migration 1...")
	users_collection := handler.Session.DB(conf.Main.Database.Name).C("users")
	users_collection.UpdateAll(bson.M{}, bson.M{"$set": bson.M{"states": bson.M{}}})

}
Exemplo n.º 2
0
func TestBot(t *testing.T) {
	conf := c.ReadConfig()
	var test = flag.Bool("test", false, "go in test use?")
	flag.Parse()
	DEBUG = true
	d.DELETE_DB = *test
	log.Printf("Is test? [%+v] Will delete db? [%+v]", *test, d.DELETE_DB)
	if d.DELETE_DB {
		log.Println("!start at test mode!")
		conf.Main.Database.Name = conf.Main.Database.Name + "_test"
	}
	db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name)

	for _, shop_conf := range conf.Shops {
		bot_context := sh.FormShopCommands(db, &shop_conf)
		shop_controller := FormBotController(bot_context)
		shop_route := fmt.Sprintf("/shop/%v", shop_conf.Name)
		log.Println("will wait requests at :", shop_route)
		http.HandleFunc(shop_route, shop_controller)
	}

	server_address := fmt.Sprintf(":%v", conf.Main.Port)
	s.StartAfter(func() (string, bool) {
		return "", db.Check()
	}, func() {
		log.Printf("\nStart listen and serving at: %v\n", server_address)
		server := &http.Server{
			Addr: server_address,
		}

		log.Fatal(server.ListenAndServe())
	})

	log.Printf("will send requests....")

	addr := fmt.Sprintf("http://localhost:%v/shop/test_shop", conf.Main.Port)
	send_post("shop_balance_ok.json", addr)
	send_post("shop_balance_error.json", addr)
	send_post("request_commands.json", addr)
	t.Log("test ended...")
}
func main() {
	conf := c.ReadConfig()
	handler := db.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name)
	s.StartAfter(func() (string, bool) {
		return "", handler.Check()
	}, func() {
		log.Printf("connection established....")
	})

	log.Println("Starting migration 0...")
	orders_collection := handler.Session.DB(conf.Main.Database.Name).C("orders")
	err := orders_collection.DropIndex("order_id")
	if err != nil {
		panic(err)
	}
	err = orders_collection.EnsureIndex(mgo.Index{
		Key:        []string{"order_id"},
		Background: true,
		Unique:     false,
		DropDups:   true,
	})
	log.Printf("Index for order_id field is recreated...%v", err)
}