refac: use embed instead of go-bindata, secure closing of transactions
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package sensor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -184,7 +185,7 @@ func addSensor(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// add sensor entry to list
|
||||
err = repo.AddSensors(sensor)
|
||||
err = repo.AddSensors(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -227,7 +228,21 @@ func disableSensor(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return repo.DisableSensorsByNames(args...)
|
||||
s, err := repo.GetSensorsByNames(context.Background(), args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range s {
|
||||
s[i].Enabled = false
|
||||
}
|
||||
|
||||
err = repo.UpdateSensors(context.Background(), s...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func enableSensor(cmd *cobra.Command, args []string) error {
|
||||
@ -259,7 +274,21 @@ func enableSensor(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return repo.EnableSensorsByNames(args...)
|
||||
s, err := repo.GetSensorsByNames(context.Background(), args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range s {
|
||||
s[i].Enabled = true
|
||||
}
|
||||
|
||||
err = repo.UpdateSensors(context.Background(), s...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func listSensors(cmd *cobra.Command, args []string) error {
|
||||
@ -292,7 +321,7 @@ func listSensors(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// add sensor entry to list
|
||||
sensors, err := repo.GetSensorsByDeviceID(cnf.DeviceID)
|
||||
sensors, err := repo.GetSensorsByDeviceIDs(context.Background(), cnf.DeviceID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -334,7 +363,7 @@ func removeSensor(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return repo.RemoveSensorsByNames(args...)
|
||||
return repo.RemoveSensorsByNames(context.Background(), args...)
|
||||
}
|
||||
|
||||
func renameSensor(cmd *cobra.Command, args []string) error {
|
||||
@ -366,5 +395,20 @@ func renameSensor(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return repo.RenameSensors(args[0], args[1])
|
||||
s, err := repo.GetSensorsByNames(context.Background(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range s {
|
||||
s[i].Name = args[1]
|
||||
}
|
||||
|
||||
err = repo.UpdateSensors(context.Background(), s...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user