1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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"})
}
|