Example #1
0
func main() {
	neo, err := neo4j.Connect("http://localhost:7474/db/data")
	log.Println("Connecting")
	if err != nil {
		log.Fatalln("Could not connect to database")
		return
	}
	log.Println("Checking index: users")

	nodes := neo.Nodes
	initUsers(nodes)
	initTasks(nodes)
}
Example #2
0
func Connect(uri string) *DataBase {
	url, err := url.Parse(uri)
	if err != nil {
		panic(err)
	}
	connection, err := neo4j.Connect(uri)
	if err != nil {
		panic(err)
	}
	db := DataBase{url, connection}

	return &db
}
Example #3
0
func main() {
	log.SetFlags(log.Ltime | log.Lshortfile)
	//
	// Configuration
	//
	port := env.StringDefault("PORT", "9000")
	pwd := env.StringDefault("PWD", "/app")
	mongoUrl := env.StringDefault("MONGOLAB_URI", "localhost")
	neoUrl := env.StringDefault("NEO4J_URL", "http://localhost:7474/db/data")
	statPrefix = env.StringDefault("STATHAT_PREFIX", "")
	ezkey = env.StringDefault("STATHAT_EZKEY", "")
	//
	// Connect to MongoDB
	//
	log.Println("Connecting to MongoDB on " + mongoUrl + "...")
	session, err := mgo.Dial(mongoUrl)
	if err != nil {
		log.Panicln(err)
	}
	defer session.Close()
	mongo = session.DB("")
	_, err = mongo.CollectionNames()
	if err != nil {
		log.Println("Setting db name to 'decisions'.")
		mongo = session.DB("decisions")
	}
	//
	// Connect to Neo4j
	//
	log.Println("Connecting to Neo4j on " + neoUrl + "...")
	neo, err = neo4j.Connect(neoUrl)
	if err != nil {
		log.Println("Cannot connect to Neo4j:")
		log.Println(err)
	}
	//
	// Routing
	//
	mux := pat.New()
	mux.Post("/decide", track(http.HandlerFunc(Decide), "/v1/decide"))
	http.Handle("/v1/", http.StripPrefix("/v1", mux))
	http.Handle("/", http.FileServer(http.Dir(pwd+"/app")))
	//
	// Start Webserver
	//
	log.Println("Starting webserver on port " + port + "...")
	err = http.ListenAndServe(":"+port, nil)
	if err != nil {
		log.Panicln(err)
	}
}