Konfi-Castle-Kasino/pkg/models/metric.go

32 lines
700 B
Go
Raw Normal View History

2019-09-14 17:15:41 +00:00
package models
import "github.com/labstack/gommon/log"
2019-09-15 14:06:49 +00:00
// Metric is the structure for metrics
2019-09-14 17:15:41 +00:00
type Metric struct {
ID int64 `xorm:"pk autoincr" json:"id" form:"id"`
Kcoins int64 `xorm:"bigint(11)"`
CommunityID int64 `xorm:"bigint(11)"`
CreatedUnix int64 `xorm:"created"`
}
2019-09-15 14:06:49 +00:00
// AddMetric saves a new metric point
2019-09-14 17:15:41 +00:00
func AddMetric() {
allCommunites := []Community{}
err := x.Find(&allCommunites)
if err != nil {
log.Error("Error getting metric data", err)
}
for _, community := range allCommunites {
m := Metric{
Kcoins: community.KCoins,
CommunityID: community.ID,
}
_, err := x.Insert(m)
if err != nil {
log.Error("Error saving metrics", err)
}
}
}