yats.git

ref: 71d00b420855a9d50fc681762352a5a55a2fb86c

rest/rest-metric.go


 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
package rest

import (
	"fmt"
	"net/http"
	"yats/db"

	"github.com/gin-gonic/gin"
)

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(idClient, metricName, metricValue)

	c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "OK"})
}

func WriteMetricAt(c *gin.Context) {
	var metric db.Metric

	if err := c.BindJSON(&metric); err != nil {
		return
	}

	fmt.Printf("%s / %s / %s", metric.ID_client, metric.Name, metric.Value)
	db.SaveMetric(metric.ID_client, metric.Name, metric.Value)

	c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "OK"})
}