From 3d07cbc9ba7cdb7a16707fa85f3521f06daa51ac Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Sat, 15 Jun 2019 16:42:54 +0200 Subject: [PATCH] feat(daemon): new flag to set compression --- cmd/daemon/daemon.go | 5 +++-- pkg/daemon/daemon.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/daemon/daemon.go b/cmd/daemon/daemon.go index 3a2e8bb..9347ed0 100644 --- a/cmd/daemon/daemon.go +++ b/cmd/daemon/daemon.go @@ -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") } diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index a7f4431..0f34eda 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -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) }