fix: implement repository pkg

This commit is contained in:
2020-05-21 17:40:24 +02:00
parent fb916c94ae
commit 8f1c7b10f7
50 changed files with 1619 additions and 178 deletions

View File

@ -1,7 +1,6 @@
package config
import (
"context"
"fmt"
"os"
"path/filepath"
@ -10,7 +9,6 @@ import (
"time"
"github.com/volker-raschek/flucky/pkg/internal/format"
"github.com/volker-raschek/flucky/pkg/storage"
uuid "github.com/satori/go.uuid"
"github.com/volker-raschek/flucky/pkg/types"
@ -159,12 +157,7 @@ func (cnf *Config) GetSensorByID(id string) *types.Sensor {
// RemoveSensor deletes a sensor by its name or its unique UUID, If definitive
// is set to true, the sensor will not only be removed in the configuration file
// but also in the backend.
func (cnf *Config) RemoveSensor(name string, definitive bool) error {
backend, err := storage.New(cnf.StorageEndpoint, nil)
if err != nil {
return err
}
func (cnf *Config) RemoveSensor(name string) error {
for i, sensor := range cnf.Sensors {
// remove machted name
@ -172,13 +165,6 @@ func (cnf *Config) RemoveSensor(name string, definitive bool) error {
sensor.Name == name {
cnf.Sensors = append(cnf.Sensors[:i], cnf.Sensors[i+1:]...)
if definitive {
err = backend.RemoveSensorByName(context.Background(), name)
if err != nil {
return err
}
}
return nil
}
// remove machted uuid
@ -186,13 +172,6 @@ func (cnf *Config) RemoveSensor(name string, definitive bool) error {
sensor.ID == name {
cnf.Sensors = append(cnf.Sensors[:i], cnf.Sensors[i+1:]...)
if definitive {
err = backend.RemoveSensorByID(context.Background(), name)
if err != nil {
return err
}
}
return nil
}
}