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:
2019-12-07 16:53:49 +01:00
parent afe55b3d33
commit dbef4f8241
30 changed files with 959 additions and 882 deletions

View File

@ -1,13 +1,7 @@
package db
import (
"context"
"log"
"github.com/Masterminds/semver"
"github.com/go-flucky/flucky/pkg/config"
database "github.com/go-flucky/flucky/pkg/storage/db"
"github.com/go-flucky/flucky/pkg/types"
"github.com/spf13/cobra"
)
@ -22,33 +16,33 @@ var dbCmd = &cobra.Command{
Short: "Operates with the configured database",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
cnf, err := config.Read(*configFile)
if err != nil {
log.Fatalln(err)
}
// // read configuration
// cnf, err := config.Read(*configFile)
// if err != nil {
// log.Fatalln(err)
// }
postgresDB, err := database.New(cnf.DatabaseSettings)
if err != nil {
log.Fatalf("%v", err)
}
// postgresDB, err := database.New(cnf.DatabaseSettings)
// if err != nil {
// log.Fatalf("%v", err)
// }
ctx := context.Background()
// ctx := context.Background()
devices := []*types.Device{
&types.Device{
DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
DeviceName: "raspberr-pi",
},
&types.Device{
DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
DeviceName: "raspberr-pi",
},
}
// devices := []*types.Device{
// &types.Device{
// DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
// DeviceName: "raspberr-pi",
// },
// &types.Device{
// DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
// DeviceName: "raspberr-pi",
// },
// }
if err := postgresDB.InsertDevices(ctx, devices); err != nil {
log.Fatalln(err)
}
// if err := postgresDB.InsertDevices(ctx, devices); err != nil {
// log.Fatalln(err)
// }
},
}