Better naming, distingiush between "service" and "backend"

This commit is contained in:
Philipp Wolfer 2023-11-19 22:54:42 +01:00
parent 6e330daf06
commit 8b227cb514
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
5 changed files with 20 additions and 20 deletions

View file

@ -28,10 +28,10 @@ import (
// beamCmd represents the beam command // beamCmd represents the beam command
var beamCmd = &cobra.Command{ var beamCmd = &cobra.Command{
Use: "beam", Use: "beam",
Short: "Transfer data between two backends", Short: "Transfer data between two services",
Long: `Transfers data (listens, loves) between two configured backends. 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.`, the data.`,
// Run: func(cmd *cobra.Command, args []string) { }, // Run: func(cmd *cobra.Command, args []string) { },
} }
@ -43,9 +43,9 @@ func init() {
// Cobra supports Persistent Flags which will work for this command // Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.: // 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.MarkPersistentFlagRequired("from")
beamCmd.PersistentFlags().StringP("to", "t", "", "Target backend configuration (required)") beamCmd.PersistentFlags().StringP("to", "t", "", "Target service configuration (required)")
beamCmd.MarkPersistentFlagRequired("to") beamCmd.MarkPersistentFlagRequired("to")
beamCmd.PersistentFlags().Int64P("timestamp", "s", 0, "Only import data newer then given Unix timestamp") beamCmd.PersistentFlags().Int64P("timestamp", "s", 0, "Only import data newer then given Unix timestamp")

View file

@ -36,8 +36,8 @@ import (
// listensCmd represents the listens command // listensCmd represents the listens command
var listensCmd = &cobra.Command{ var listensCmd = &cobra.Command{
Use: "listens", Use: "listens",
Short: "Transfer listens between two backends", Short: "Transfer listens between two services",
Long: `Transfers listens between two configured backends.`, Long: `Transfers listens between two configured services.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
sourceName, sourceConfig := getConfigFromFlag(cmd, "from") sourceName, sourceConfig := getConfigFromFlag(cmd, "from")
targetName, targetConfig := getConfigFromFlag(cmd, "to") targetName, targetConfig := getConfigFromFlag(cmd, "to")

View file

@ -36,8 +36,8 @@ import (
// lovesCmd represents the loves command // lovesCmd represents the loves command
var lovesCmd = &cobra.Command{ var lovesCmd = &cobra.Command{
Use: "loves", Use: "loves",
Short: "Transfer loves between two backends", Short: "Transfer loves between two services",
Long: `Transfers loves between two configured backends.`, Long: `Transfers loves between two configured services.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
sourceName, sourceConfig := getConfigFromFlag(cmd, "from") sourceName, sourceConfig := getConfigFromFlag(cmd, "from")
targetName, targetConfig := getConfigFromFlag(cmd, "to") targetName, targetConfig := getConfigFromFlag(cmd, "to")

View file

@ -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) { func (db Database) GetImportTimestamp(source string, target string, entity string) (time.Time, error) {
result := ImportTimestamp{ result := ImportTimestamp{
SourceBackend: source, SourceService: source,
TargetBackend: target, TargetService: target,
Entity: entity, Entity: entity,
} }
db.db.Limit(1).Find(&result) err := db.db.Limit(1).Find(&result).Error
return result.Timestamp, nil return result.Timestamp, err
} }
func (db Database) SetImportTimestamp(source string, target string, entity string, timestamp time.Time) error { func (db Database) SetImportTimestamp(source string, target string, entity string, timestamp time.Time) error {
entry := ImportTimestamp{ entry := ImportTimestamp{
SourceBackend: source, SourceService: source,
TargetBackend: target, TargetService: target,
Entity: entity, Entity: entity,
Timestamp: timestamp, Timestamp: timestamp,
} }
db.db.Clauses(clause.OnConflict{ err := db.db.Clauses(clause.OnConflict{
DoUpdates: clause.AssignmentColumns([]string{"timestamp", "updated_at"}), DoUpdates: clause.AssignmentColumns([]string{"timestamp", "updated_at"}),
}).Create(&entry) }).Create(&entry).Error
return nil return err
} }

View file

@ -27,8 +27,8 @@ import (
) )
type ImportTimestamp struct { type ImportTimestamp struct {
SourceBackend string `gorm:"primaryKey"` SourceService string `gorm:"primaryKey"`
TargetBackend string `gorm:"primaryKey"` TargetService string `gorm:"primaryKey"`
Entity string `gorm:"primaryKey"` Entity string `gorm:"primaryKey"`
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time