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
46
47
48
49
50
51
52
|
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"})
}
|