From 8b227cb5145a3189611793c49c8d6ea46d25ae0f Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 19 Nov 2023 22:54:42 +0100 Subject: [PATCH] Better naming, distingiush between "service" and "backend" --- cmd/beam.go | 10 +++++----- cmd/listens.go | 4 ++-- cmd/loves.go | 4 ++-- storage/database.go | 18 +++++++++--------- storage/models.go | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/beam.go b/cmd/beam.go index c38703d..a29a8f1 100644 --- a/cmd/beam.go +++ b/cmd/beam.go @@ -28,10 +28,10 @@ import ( // beamCmd represents the beam command var beamCmd = &cobra.Command{ Use: "beam", - Short: "Transfer data between two backends", - Long: `Transfers data (listens, loves) between two configured backends. + Short: "Transfer data between two services", + Long: `Transfers data (listens, loves) between two configured services. -The backends must be configured and be able to handle export and import of +The services must be configured and be able to handle export and import of the data.`, // Run: func(cmd *cobra.Command, args []string) { }, } @@ -43,9 +43,9 @@ func init() { // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: - beamCmd.PersistentFlags().StringP("from", "f", "", "Source backend configuration (required)") + beamCmd.PersistentFlags().StringP("from", "f", "", "Source service configuration (required)") beamCmd.MarkPersistentFlagRequired("from") - beamCmd.PersistentFlags().StringP("to", "t", "", "Target backend configuration (required)") + beamCmd.PersistentFlags().StringP("to", "t", "", "Target service configuration (required)") beamCmd.MarkPersistentFlagRequired("to") beamCmd.PersistentFlags().Int64P("timestamp", "s", 0, "Only import data newer then given Unix timestamp") diff --git a/cmd/listens.go b/cmd/listens.go index 9233587..395391e 100644 --- a/cmd/listens.go +++ b/cmd/listens.go @@ -36,8 +36,8 @@ import ( // listensCmd represents the listens command var listensCmd = &cobra.Command{ Use: "listens", - Short: "Transfer listens between two backends", - Long: `Transfers listens between two configured backends.`, + Short: "Transfer listens between two services", + Long: `Transfers listens between two configured services.`, Run: func(cmd *cobra.Command, args []string) { sourceName, sourceConfig := getConfigFromFlag(cmd, "from") targetName, targetConfig := getConfigFromFlag(cmd, "to") diff --git a/cmd/loves.go b/cmd/loves.go index 74f4030..5a70e6e 100644 --- a/cmd/loves.go +++ b/cmd/loves.go @@ -36,8 +36,8 @@ import ( // lovesCmd represents the loves command var lovesCmd = &cobra.Command{ Use: "loves", - Short: "Transfer loves between two backends", - Long: `Transfers loves between two configured backends.`, + Short: "Transfer loves between two services", + Long: `Transfers loves between two configured services.`, Run: func(cmd *cobra.Command, args []string) { sourceName, sourceConfig := getConfigFromFlag(cmd, "from") targetName, targetConfig := getConfigFromFlag(cmd, "to") diff --git a/storage/database.go b/storage/database.go index 0b43e09..9d92d52 100644 --- a/storage/database.go +++ b/storage/database.go @@ -58,23 +58,23 @@ func New(dsn string) (db Database, err error) { func (db Database) GetImportTimestamp(source string, target string, entity string) (time.Time, error) { result := ImportTimestamp{ - SourceBackend: source, - TargetBackend: target, + SourceService: source, + TargetService: target, Entity: entity, } - db.db.Limit(1).Find(&result) - return result.Timestamp, nil + err := db.db.Limit(1).Find(&result).Error + return result.Timestamp, err } func (db Database) SetImportTimestamp(source string, target string, entity string, timestamp time.Time) error { entry := ImportTimestamp{ - SourceBackend: source, - TargetBackend: target, + SourceService: source, + TargetService: target, Entity: entity, Timestamp: timestamp, } - db.db.Clauses(clause.OnConflict{ + err := db.db.Clauses(clause.OnConflict{ DoUpdates: clause.AssignmentColumns([]string{"timestamp", "updated_at"}), - }).Create(&entry) - return nil + }).Create(&entry).Error + return err } diff --git a/storage/models.go b/storage/models.go index 348a9d4..3f8271f 100644 --- a/storage/models.go +++ b/storage/models.go @@ -27,8 +27,8 @@ import ( ) type ImportTimestamp struct { - SourceBackend string `gorm:"primaryKey"` - TargetBackend string `gorm:"primaryKey"` + SourceService string `gorm:"primaryKey"` + TargetService string `gorm:"primaryKey"` Entity string `gorm:"primaryKey"` CreatedAt time.Time UpdatedAt time.Time