package logfile import ( "path/filepath" "github.com/go-flucky/flucky/pkg/internal/format" "github.com/go-flucky/flucky/pkg/types" ) // var validUUID = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") // Append adds an array of several measured values to a logfile func Append(logfile Logfile, measuredValues []*types.MeasuredValue) error { allMeasuredValues, err := logfile.Read() if err != nil { return err } allMeasuredValues = append(allMeasuredValues, measuredValues...) err = logfile.Write(allMeasuredValues) if err != nil { return err } return nil } // New returns a log file with basic functions for reading and writing data. The // file extension of the logfile is taken into account to format the logfile // into the correct format. func New(logfile string) Logfile { ext := filepath.Ext(logfile) switch ext { case ".csv": return &csvLogfile{ logfile: logfile, } case ".json": return &jsonLogfile{ logfile: logfile, } case ".xml": return &xmlLogfile{ logfile: logfile, } default: return &jsonLogfile{ logfile: logfile, } } } func writeCreationDate(measuredValues []*types.MeasuredValue) error { now := format.FormatedTime() for _, measuredValue := range measuredValues { if measuredValue.CreationDate == nil { measuredValue.CreationDate = &now } } return nil }