示例#1
0
func main() {
	r := gin.Default()
	r.Use(RequestIdMiddleware())
	DB, err := db.Connect(db.ConnectOpts{
		Address:  fmt.Sprintf("%s:%d", os.Getenv("RETHINKDB_PORT_28015_TCP_ADDR"), 28015),
		Database: "test",
	})
	if err != nil {
		log.Fatalln(err.Error())
	}
	db.TableCreate("users").RunWrite(DB)
	db.TableCreate("resources").RunWrite(DB)
	store, err := sessions.NewRedisStore(10, "tcp", fmt.Sprintf("%s:%d", os.Getenv("REDIS_1_PORT_6379_TCP_ADDR"), 6379), "", []byte(os.Getenv("REDIS_SECRET")))
	if err != nil {
		log.Fatalln(err.Error())
	}
	gob.Register(models.User{})
	r.Use(sessions.Sessions("session", store))
	api.Init(r, DB, RequestAuthMiddleware)
	login.Init(r, DB)
	r.Any("/ping", func(c *gin.Context) {
		if DB.IsConnected() {
			c.String(200, "ok")
		} else {
			c.String(500, "not ok")
		}
	})
	r.Run(":8080") // listen and serve on 0.0.0.0:8080
}
示例#2
0
文件: data.go 项目: gauthierc/magnet
func (c *Connection) InitDatabase() {
	r.DBCreate("magnet").Exec(c.session)
	r.TableCreate("users").Exec(c.session)
	r.TableCreate("bookmarks").Exec(c.session)
	_, err := r.DB("magnet").Table("bookmarks").IndexCreate("Created").RunWrite(c.session)
	if err != nil {
		log.Printf("Error creating index: %s", err)
	}
	r.TableCreate("sessions").Exec(c.session)
}
示例#3
0
func createSchema(s *r.Session) error {
	tables, err := getTableList(s)

	if err == nil && !tables["jobs"] {
		err = r.TableCreate("jobs").Exec(s)
	}

	if err == nil && !tables["builds"] {
		err = r.TableCreate("builds").Exec(s)
	}

	return err
}
示例#4
0
// CreateTable creates a new RethinkDB table with the given name.
func CreateTable(name string) {
	resp, err := rdb.TableCreate(name).RunWrite(RDB)
	if err != nil {
		log.Printf("%s\n", err.Error())
	}
	log.Printf("%d tables created\n", resp.TablesCreated)
}
示例#5
0
文件: db.go 项目: bentranter/devtbay
// CreateTable creates a new RethinkDB table with the given name.
func (a *App) CreateTable(name string) error {
	resp, err := r.TableCreate(name).RunWrite(a.Session)
	if err != nil {
		return err
	}
	a.Logger.Printf("%d tables created\n", resp.TablesCreated)
	return nil
}
示例#6
0
func CreateTable(table string) error {
	// Create the table.
	log.L.Infof("Database: creating table %s", table)
	_, err := r.TableCreate(table).RunWrite(Session)
	if err != nil {
		return err
	}

	return nil
}
示例#7
0
func newDBConn() *rdb.Session {
	session, err := rdb.Connect(rdb.ConnectOpts{
		Address: "localhost:28015",
	})
	if err != nil {
		log.Fatalln("Error: %s", err)
		return nil
	}

	resp, _ := rdb.TableCreate(tableName).RunWrite(session)
	log.Println("Tables created: ", resp.TablesCreated)

	return session
}
示例#8
0
func initDb() {
	var session *r.Session

	session, err := r.Connect(r.ConnectOpts{
		Address: "localhost:28015",
	})
	if err != nil {
		log.Fatalln(err.Error())
	}

	session.SetMaxOpenConns(5)

	r.TableDrop("cars").Run(session)

	resp, err := r.TableCreate("cars").RunWrite(session)
	if err != nil {
		log.Println(err)
	}

	fmt.Printf("%d table created\n", resp.TablesCreated)

	s = session
}
示例#9
0
文件: resource.go 项目: javinc/puto
func init() {
	r.TableCreate(resourceName).Run(module.RSession)
}