35 lines
633 B
Go
35 lines
633 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type IncrementMetric struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Service string `json:"service"`
|
|
Environment string `json:"environment"`
|
|
Name string `json:"name"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
func AddIncrementMetric(metric IncrementMetric) error {
|
|
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO increments")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = batch.Append(
|
|
metric.Timestamp,
|
|
metric.Service,
|
|
metric.Environment,
|
|
metric.Name,
|
|
metric.Count,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return batch.Send()
|
|
}
|