fix(pkg/storage): write creation date in storage pkg
This commit is contained in:
parent
c266117785
commit
3581424bd2
@ -112,8 +112,6 @@ func (cl *csvLogfile) Write(measuredValues []*types.MeasuredValue) error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
writeCreationDate(measuredValues)
|
||||
|
||||
w := csv.NewWriter(f)
|
||||
|
||||
for _, measuredValue := range measuredValues {
|
||||
|
@ -52,8 +52,6 @@ func (jl *jsonLogfile) Write(measuredValues []*types.MeasuredValue) error {
|
||||
}
|
||||
}
|
||||
|
||||
writeCreationDate(measuredValues)
|
||||
|
||||
f, err := os.Create(jl.logfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v %v: %v", errorLogfileCreate, jl.logfile, err)
|
||||
|
@ -2,9 +2,6 @@ package logfile
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-flucky/flucky/pkg/internal/format"
|
||||
"github.com/go-flucky/flucky/pkg/types"
|
||||
)
|
||||
|
||||
// New returns a log file with basic functions for reading and writing data. The
|
||||
@ -31,13 +28,3 @@ func New(logfile string) Logfile {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeCreationDate(measuredValues []*types.MeasuredValue) error {
|
||||
now := format.FormatedTime()
|
||||
for _, measuredValue := range measuredValues {
|
||||
if measuredValue.CreationDate == nil {
|
||||
measuredValue.CreationDate = &now
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ func (xl *xmlLogfile) Write(measuredValues []*types.MeasuredValue) error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
writeCreationDate(measuredValues)
|
||||
|
||||
cachedMeasuredValues := new(MeasuredValues)
|
||||
|
||||
for _, measuredValue := range measuredValues {
|
||||
|
@ -106,24 +106,28 @@ func Round(measuredValues []*types.MeasuredValue, round float64) {
|
||||
// data. The scheme must be matched to a storage provider, if the scheme is not
|
||||
// implemented, the function returns an error
|
||||
func Write(ctx context.Context, measuredValues []*types.MeasuredValue, storageEndpoint *url.URL) error {
|
||||
writeCreationDate(measuredValues)
|
||||
switch storageEndpoint.Scheme {
|
||||
case "file":
|
||||
measuredValueLogfile := logfile.New(storageEndpoint.Path)
|
||||
storedMeasuredValues, err := measuredValueLogfile.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
storedMeasuredValues = append(storedMeasuredValues, measuredValues...)
|
||||
return measuredValueLogfile.Write(storedMeasuredValues)
|
||||
return measuredValueLogfile.Write(measuredValues)
|
||||
case "postgres":
|
||||
database, err := db.New(storageEndpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer database.Close()
|
||||
if err := database.InsertMeasuredValues(ctx, measuredValues); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return database.InsertMeasuredValues(ctx, measuredValues)
|
||||
default:
|
||||
return fmt.Errorf("No supported scheme")
|
||||
}
|
||||
}
|
||||
|
||||
func writeCreationDate(measuredValues []*types.MeasuredValue) {
|
||||
now := format.FormatedTime()
|
||||
for _, measuredValue := range measuredValues {
|
||||
if measuredValue.CreationDate == nil {
|
||||
measuredValue.CreationDate = &now
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user