package main import ( "fmt" "net/http" "os" "yats/config" "yats/db" "github.com/gin-gonic/gin" "github.com/gocql/gocql" ) var session *gocql.Session func RestService(c config.Configuration) { 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 session, _ := cluster.CreateSession() defer session.Close() /// address := c.REST_ADDRESS router := gin.Default() router.Use(CorsHeaders()) router.SetTrustedProxies([]string{"127.0.0.1"}) gin.SetMode(gin.ReleaseMode) router.GET("/metric/:idClient/:metricName/:metricValue", writeMetric) router.Run(address) //router.RunTLS(address, c.CertFile, c.KeyFile) } func writeMetric(c *gin.Context) { idClient := c.Param("idClient") metricName := c.Param("metricName") metricValue := c.Param("metricValue") fmt.Printf("%s / %s / %s", idClient, metricName, metricValue) db.SaveMetric(session, idClient, metricName, metricValue) c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "OK"}) }