fix(pkg/config): use storage endpoints
changes: - Only one storage endpoint can be defined. This consists of a URL which can be used to specify whether the data is to be stored in a file or in a database.
This commit is contained in:
		@@ -1,16 +1,16 @@
 | 
			
		||||
package humidity
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/storage/logfile"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/storage"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/types"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/cli"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/config"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/rgbled"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -26,19 +26,14 @@ var listTemperatureCmd = &cobra.Command{
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		logfile := logfile.New(cnf.Logfile)
 | 
			
		||||
 | 
			
		||||
		rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
 | 
			
		||||
		if err := rgbled.Logfile(rgbLEDs); err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		measuredValues, err := logfile.Read()
 | 
			
		||||
		ctx := context.Background()
 | 
			
		||||
		storageEndpoint, err := cnf.GetStorageEndpointURL()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := rgbled.Off(rgbLEDs); err != nil {
 | 
			
		||||
		measuredValues, err := storage.Read(ctx, storageEndpoint)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/storage/logfile"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/storage"
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/types"
 | 
			
		||||
 | 
			
		||||
	"github.com/go-flucky/flucky/pkg/cli"
 | 
			
		||||
@@ -56,8 +56,12 @@ var readHumidityCmd = &cobra.Command{
 | 
			
		||||
		cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
 | 
			
		||||
 | 
			
		||||
		if logs {
 | 
			
		||||
			measuredValuesLogfile := logfile.New(cnf.Logfile)
 | 
			
		||||
			err := logfile.Append(measuredValuesLogfile, measuredValues)
 | 
			
		||||
			storageEndpoint, err := cnf.GetStorageEndpointURL()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Fatalln(err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			err = storage.Write(ctx, measuredValues, storageEndpoint)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Fatalln(err)
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user