package main import ( "fmt" "net/http" "yats/config" "yats/db" "github.com/gin-gonic/gin" "github.com/gocql/gocql" ) var session *gocql.Session func RestService(c config.Configuration, sess *gocql.Session) { if sess == nil { fmt.Println("sess is NULL") } session = sess 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"}) }