fix: golangci-lint and gosec warnings
This commit is contained in:
@ -11,15 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
importSensors bool
|
||||
importHumidities bool
|
||||
importPressures bool
|
||||
importTemperatures bool
|
||||
)
|
||||
|
||||
func InitCmd(cmd *cobra.Command) error {
|
||||
|
||||
importCmd := &cobra.Command{
|
||||
Use: "import",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
@ -34,7 +26,6 @@ import sqlite3:///var/cache/flucky/sqlite3.db postgres://user:password@host:port
|
||||
}
|
||||
|
||||
func importSources(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
|
||||
// Execute a
|
||||
func Execute(version string) error {
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "flucky",
|
||||
PersistentPreRunE: preRunError,
|
||||
@ -59,13 +58,11 @@ func Execute(version string) error {
|
||||
}
|
||||
|
||||
func preRunError(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile := cmd.Flag("config").Value.String()
|
||||
|
||||
// check if config file exists
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
|
||||
// Time must be truncted for postgres. Postgres currently does not support
|
||||
// Time must be truncated for postgres. Postgres currently does not support
|
||||
// nanoseconds which is automatically include into the go time object
|
||||
postgresTimeStamp := time.Now()
|
||||
location, err := time.LoadLocation("Europe/Berlin")
|
||||
|
@ -98,7 +98,6 @@ flucky sensor rename f98b00ea-a9b2-4e00-924f-113859d0af2d outdoor`,
|
||||
}
|
||||
|
||||
func addSensor(cmd *cobra.Command, args []string) error {
|
||||
|
||||
sensor := &types.Sensor{
|
||||
ID: uuid.NewV4().String(),
|
||||
Name: args[0],
|
||||
@ -200,7 +199,6 @@ func addSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func disableSensor(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
@ -246,7 +244,6 @@ func disableSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func enableSensor(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
@ -292,7 +289,6 @@ func enableSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func listSensors(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
@ -335,7 +331,6 @@ func listSensors(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeSensor(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
@ -367,7 +362,6 @@ func removeSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func renameSensor(cmd *cobra.Command, args []string) error {
|
||||
|
||||
configFile, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return fmt.Errorf("No config file defined")
|
||||
@ -410,5 +404,4 @@ func renameSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
@ -97,26 +97,22 @@ func readTemperature(cmd *cobra.Command, args []string) error {
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case err, open := <-errorChannel:
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
flogger.Error("%v", err)
|
||||
err, open := <-errorChannel
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
flogger.Error("%v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
measuredValues := make([]*types.MeasuredValue, 0)
|
||||
LOOP:
|
||||
for {
|
||||
select {
|
||||
case measuredValue, open := <-measuredValueChannel:
|
||||
if !open {
|
||||
break LOOP
|
||||
}
|
||||
measuredValues = append(measuredValues, measuredValue)
|
||||
measuredValue, open := <-measuredValueChannel
|
||||
if !open {
|
||||
break LOOP
|
||||
}
|
||||
measuredValues = append(measuredValues, measuredValue)
|
||||
}
|
||||
|
||||
err = cli.PrintMeasuredValues(measuredValues, os.Stdout)
|
||||
|
Reference in New Issue
Block a user