feat(daemon): new flag to set compression

This commit is contained in:
Markus Pesch 2019-06-15 16:42:54 +02:00
parent 17e5cef737
commit 3d07cbc9ba
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 6 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
)
var compression bool
var configPath string
var daemonCmd = &cobra.Command{
@ -20,7 +21,7 @@ var daemonCmd = &cobra.Command{
log.Fatalln(err)
}
err = daemon.Start(cnf)
err = daemon.Start(cnf, compression)
if err != nil {
panic(err)
}
@ -30,7 +31,7 @@ var daemonCmd = &cobra.Command{
func InitCmd(cmd *cobra.Command, cnfPath string) {
configPath = cnfPath
cmd.AddCommand(daemonCmd)
daemonCmd.Flags().BoolVarP(&compression, "compression", "c", true, "Compress measured values")
}

View File

@ -15,7 +15,7 @@ import (
)
// Start the daemon
func Start(cnf *config.Configuration) error {
func Start(cnf *config.Configuration, compression bool) error {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
@ -37,7 +37,7 @@ func Start(cnf *config.Configuration) error {
log.Printf("Write measured values into logfile")
log.Printf("%v new measured temperature values", len(temperatures))
err := logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, true)
err := logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, compression)
if err != nil {
return fmt.Errorf("Can not save temperatures: %v", err)
}
@ -48,7 +48,7 @@ func Start(cnf *config.Configuration) error {
temperatures = append(temperatures, temperature)
} else {
log.Printf("Temperature Channel closed. Write remaining values into the logfile")
err := logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, true)
err := logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, compression)
if err != nil {
return fmt.Errorf("Can not save temperatures: %v", err)
}