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()
|
defer f.Close()
|
||||||
|
|
||||||
writeCreationDate(measuredValues)
|
|
||||||
|
|
||||||
w := csv.NewWriter(f)
|
w := csv.NewWriter(f)
|
||||||
|
|
||||||
for _, measuredValue := range measuredValues {
|
for _, measuredValue := range measuredValues {
|
||||||
|
@ -52,8 +52,6 @@ func (jl *jsonLogfile) Write(measuredValues []*types.MeasuredValue) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeCreationDate(measuredValues)
|
|
||||||
|
|
||||||
f, err := os.Create(jl.logfile)
|
f, err := os.Create(jl.logfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v %v: %v", errorLogfileCreate, jl.logfile, err)
|
return fmt.Errorf("%v %v: %v", errorLogfileCreate, jl.logfile, err)
|
||||||
|
@ -2,9 +2,6 @@ package logfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"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
|
// 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()
|
defer f.Close()
|
||||||
|
|
||||||
writeCreationDate(measuredValues)
|
|
||||||
|
|
||||||
cachedMeasuredValues := new(MeasuredValues)
|
cachedMeasuredValues := new(MeasuredValues)
|
||||||
|
|
||||||
for _, measuredValue := range 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
|
// data. The scheme must be matched to a storage provider, if the scheme is not
|
||||||
// implemented, the function returns an error
|
// implemented, the function returns an error
|
||||||
func Write(ctx context.Context, measuredValues []*types.MeasuredValue, storageEndpoint *url.URL) error {
|
func Write(ctx context.Context, measuredValues []*types.MeasuredValue, storageEndpoint *url.URL) error {
|
||||||
|
writeCreationDate(measuredValues)
|
||||||
switch storageEndpoint.Scheme {
|
switch storageEndpoint.Scheme {
|
||||||
case "file":
|
case "file":
|
||||||
measuredValueLogfile := logfile.New(storageEndpoint.Path)
|
measuredValueLogfile := logfile.New(storageEndpoint.Path)
|
||||||
storedMeasuredValues, err := measuredValueLogfile.Read()
|
return measuredValueLogfile.Write(measuredValues)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
storedMeasuredValues = append(storedMeasuredValues, measuredValues...)
|
|
||||||
return measuredValueLogfile.Write(storedMeasuredValues)
|
|
||||||
case "postgres":
|
case "postgres":
|
||||||
database, err := db.New(storageEndpoint)
|
database, err := db.New(storageEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer database.Close()
|
defer database.Close()
|
||||||
if err := database.InsertMeasuredValues(ctx, measuredValues); err != nil {
|
return database.InsertMeasuredValues(ctx, measuredValues)
|
||||||
return err
|
default:
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Errorf("No supported scheme")
|
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