Exemplo n.º 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
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 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
}
Exemplo n.º 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)
}
Exemplo n.º 5
0
// 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 9
0
func init() {
	r.TableCreate(resourceName).Run(module.RSession)
}