Exemple #1
0
func main() {
	flag.Parse()

	setupLogging(*HTTPLogLocation)
	log.Printf("Now serving on http://localhost:%d\n", *port)

	runtime.GOMAXPROCS(runtime.NumCPU())

	session, err := r.Connect(*DBConnection, "urls")
	if err != nil {
		log.Fatal(err)
	}
	defer session.Close()

	router := mux.NewRouter()
	// UUID format
	router.HandleFunc("/{key:[a-z0-9-]+}", func(w http.ResponseWriter, request *http.Request) {
		views.EmbiggenHandler(w, request, session)
	}).Methods("GET")
	router.HandleFunc("/", func(w http.ResponseWriter, request *http.Request) {
		views.ShortenHandler(w, request, session)
	}).Methods("POST")
	router.HandleFunc("/", views.IndexHandler).Methods("GET")
	http.Handle("/", router)
	err = http.ListenAndServe(fmt.Sprintf(":%d", *port), handlers.LoggingHandler(HTTPLogger, http.DefaultServeMux))
	if err != nil {
		log.Fatal(err)
	}
}
func main() {
	var err error
	connect_string := fmt.Sprintf("%s:%s", []byte(RDB_HOST), []byte(RDB_PORT))
	session, err = rethink.Connect(connect_string, TODO_DB)
	if err != nil {
		fmt.Println("Error connecting:", err)
		return
	}

	err = setupDatabase()
	if err != nil {
		fmt.Println("Unable to set up database:", err)
	}

	r := mux.NewRouter()
	// API handlers
	r.HandleFunc("/todos/{id}", todoDetailHandler).Methods("GET")
	r.HandleFunc("/todos/{id}", todoUpdateHandler).Methods("PUT")
	r.HandleFunc("/todos/{id}", todoDeleteHandler).Methods("DELETE")
	r.HandleFunc("/todos", todoListHandler).Methods("GET")
	r.HandleFunc("/todos", todoCreateHandler).Methods("POST")

	// Front-end handlers
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
	r.HandleFunc("/", indexHandler)

	http.ListenAndServe("0.0.0.0:8000", r)
}
Exemple #3
0
func main() {
	// To access a RethinkDB database, you connect to it with the Connect function
	session, err := r.Connect("localhost:28015", "company_info")
	if err != nil {
		fmt.Println("error connecting:", err)
		return
	}

	var response []Employee
	// Using .All(), we can read the entire response into a slice, without iteration
	err = r.Table("employees").Run(session).All(&response)
	if err != nil {
		fmt.Println("err:", err)
	} else {
		fmt.Println("response:", response)
	}

	// If we want to iterate over each result individually, we can use the rows
	// object as an iterator
	rows := r.Table("employees").Run(session)
	for rows.Next() {
		var row Employee
		if err = rows.Scan(&row); err != nil {
			fmt.Println("err:", err)
			break
		}
		fmt.Println("row:", row)
	}
	if err = rows.Err(); err != nil {
		fmt.Println("err:", err)
	}
}
Exemple #4
0
func drop() {
  conn, err := r.Connect("localhost:28015", "pasahero")
  if err !=nil {
    fmt.Println("Error connection: ", err)
    return
  }
  if Name not in r.db_list().Run(conn) 
}
Exemple #5
0
func (c *Connection) SetSession(address, database string) {
	session, err := rethinkgo.Connect(address, "magnet")

	if err != nil {
		log.Fatal("Error connecting:", err)
	}

	c.session = session
}
func main() {
	r.Connect(os.Getenv("RETHINKDB_HOST"), "kanban")
	http.HandleFunc("/", hello)
	fmt.Println("listening...")
	err := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
	if err != nil {
		panic(err)
	}
}
Exemple #7
0
func DB() martini.Handler {
	return func(c martini.Context) {
		session, err := rethink.Connect("localhost:28015", "countify")
		if err != nil {
			panic(err)
		}
		c.Map(session)
		defer session.Close()
		c.Next()
	}
}
Exemple #8
0
func (self *Database) getSession() *rethinkgo.Session {
	if self.Session == nil {
		var err error
		self.Session, err = rethinkgo.Connect(self.Host+":"+self.Port, self.Name)

		if err != nil {
			log.Println("[ERROR] getSession: ", err)
			panic(err) // no, not really
		}
	}

	return self.Session
}
Exemple #9
0
func (this *Database) Init(address, database string, bufCount int) (err error) {
	this.session, err = r.Connect(address, database)
	if err != nil {
		fmt.Println("CRITICAL : Failed to connect to DB " + database)
		return
	}

	this.queue = make(chan DatabaseRequest, bufCount)

	go this.run()

	return
}
func simpleTest() {
	session, err := r.Connect("localhost:28015", "test")
	if err != nil {
		log.Fatal(err)
	}

	/*

	  err = r.DbCreate("test").Run(session).Exec()
	  if err != nil {
	    log.Fatal(err)
	  }
	*/

	err = r.TableCreate("bookmarks").Run(session).Exec()
	if err != nil {
		log.Fatal(err)
	}
}
Exemple #11
0
func initDb() {
	session, err := r.Connect(os.Getenv("WERCKER_RETHINKDB_URL"), "gettingstarted")
	if err != nil {
		log.Fatal(err)
		return
	}

	err = r.DbCreate("gettingstarted").Run(session).Exec()
	if err != nil {
		log.Println(err)
	}

	err = r.TableCreate("bookmarks").Run(session).Exec()
	if err != nil {
		log.Println(err)
	}

	sessionArray = append(sessionArray, session)
}