yats.git

commit b38279cd2f8b51d1467c421bd7dd764cd19172db

Author: Paolo Lulli <paolo@lulli.net>

WIP db session works

 rest.go | 17 +++++------------
 yats.go | 16 ++++++++--------


diff --git a/rest.go b/rest.go
index cd20a7592325592284450752604c96d9d74fa51e..dae7679fc5af27f3a84c7ab740d5a009f71e1eca 100644
--- a/rest.go
+++ b/rest.go
@@ -3,7 +3,6 @@
 import (
 	"fmt"
 	"net/http"
-	"os"
 	"yats/config"
 	"yats/db"
 
@@ -13,18 +12,12 @@ )
 
 var session *gocql.Session
 
-func RestService(c config.Configuration) {
-	configuration := config.GetConfig(os.Getenv("HOME") + "/.yats.json")
+func RestService(c config.Configuration, sess *gocql.Session) {
 
-	cluster := gocql.NewCluster(configuration.DB_HOST)
-	cluster.Authenticator = gocql.PasswordAuthenticator{Username: configuration.DB_USERNAME, Password: configuration.DB_PASSWORD}
-	cluster.Keyspace = configuration.DB_NAME
-
-	session, _ := cluster.CreateSession()
-
-	defer session.Close()
-
-	///
+	if sess == nil {
+		fmt.Println("sess is NULL")
+	}
+	session = sess
 	address := c.REST_ADDRESS
 
 	router := gin.Default()




diff --git a/yats.go b/yats.go
index bc96e9e1aa5845e0d51f4ba0710195794e58e07a..d9659421e9bab29504f4d06b9e35f2aa9043550e 100644
--- a/yats.go
+++ b/yats.go
@@ -3,21 +3,21 @@
 import (
 	"os"
 	"yats/config"
+
+	"github.com/gocql/gocql"
 )
 
 func main() {
 	configuration := config.GetConfig(os.Getenv("HOME") + "/.yats.json")
-	/*
 
+	cluster := gocql.NewCluster(configuration.DB_HOST)
+	cluster.Authenticator = gocql.PasswordAuthenticator{Username: configuration.DB_USERNAME, Password: configuration.DB_PASSWORD}
+	cluster.Keyspace = configuration.DB_NAME
 
-		cluster := gocql.NewCluster(configuration.DB_HOST)
-		cluster.Authenticator = gocql.PasswordAuthenticator{Username: configuration.DB_USERNAME, Password: configuration.DB_PASSWORD}
-		cluster.Keyspace = configuration.DB_NAME
+	session, _ := cluster.CreateSession()
 
-		session, _ := cluster.CreateSession()
+	defer session.Close()
 
-		defer session.Close()
-	*/
 	//idClient := "ClientZero"
 
 	/*
@@ -31,6 +31,6 @@ 		var metrics = db.LoadMetrics(session)
 
 		db.PrintMetrics(metrics)
 	*/
-	RestService(configuration)
+	RestService(configuration, session)
 
 }