From e03a0ff9d729876955fa7114a4587c4a9fa4de24 Mon Sep 17 00:00:00 2001 From: Michael Gaffney Date: Thu, 23 Jul 2020 17:58:41 -0400 Subject: [PATCH] Simplify SetTableName pattern (#214) --- internal/authtoken/gorm.go | 16 +++------------- internal/db/db_test/db.go | 21 +++------------------ internal/host/static/gorm.go | 28 ++++------------------------ internal/iam/auth_account.go | 7 +------ internal/iam/group.go | 7 +------ internal/iam/role.go | 7 +------ internal/iam/role_grant.go | 7 +------ internal/iam/scope.go | 7 +------ internal/iam/user.go | 7 +------ internal/oplog/oplog_test/db.go | 21 +++------------------ 10 files changed, 19 insertions(+), 109 deletions(-) diff --git a/internal/authtoken/gorm.go b/internal/authtoken/gorm.go index a8ef1db3b..6d9e24cbb 100644 --- a/internal/authtoken/gorm.go +++ b/internal/authtoken/gorm.go @@ -14,12 +14,7 @@ func (s *AuthToken) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (s *AuthToken) SetTableName(n string) { - switch n { - case "": - s.tableName = defaultAuthTokenTableName - default: - s.tableName = n - } + s.tableName = n } // TableName returns the table name for the auth token. @@ -33,10 +28,5 @@ func (s *writableAuthToken) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (s *writableAuthToken) SetTableName(n string) { - switch n { - case "": - s.tableName = defaultWritableAuthTokenTableName - default: - s.tableName = n - } -} \ No newline at end of file + s.tableName = n +} diff --git a/internal/db/db_test/db.go b/internal/db/db_test/db.go index a21f44eb8..9178cedfc 100644 --- a/internal/db/db_test/db.go +++ b/internal/db/db_test/db.go @@ -84,12 +84,7 @@ func (c *TestCar) TableName() string { return defaultCarTableName } func (c *TestCar) SetTableName(name string) { - switch name { - case "": - c.table = defaultCarTableName - default: - c.table = name - } + c.table = name } type TestRental struct { @@ -116,12 +111,7 @@ func (r *TestRental) TableName() string { return defaultRentalTableName } func (r *TestRental) SetTableName(name string) { - switch name { - case "": - r.table = defaultRentalTableName - default: - r.table = name - } + r.table = name } type TestScooter struct { @@ -155,12 +145,7 @@ func (t *TestScooter) TableName() string { } func (t *TestScooter) SetTableName(name string) { - switch name { - case "": - t.table = defaultScooterTableName - default: - t.table = name - } + t.table = name } type Cloner interface { diff --git a/internal/host/static/gorm.go b/internal/host/static/gorm.go index d661f50ef..a3450c3e4 100644 --- a/internal/host/static/gorm.go +++ b/internal/host/static/gorm.go @@ -18,12 +18,7 @@ func (c *HostCatalog) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (c *HostCatalog) SetTableName(n string) { - switch n { - case "": - c.tableName = defaultHostCatalogTableName - default: - c.tableName = n - } + c.tableName = n } // TableName returns the table name for the host. @@ -37,12 +32,7 @@ func (h *Host) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (h *Host) SetTableName(n string) { - switch n { - case "": - h.tableName = defaultHostTableName - default: - h.tableName = n - } + h.tableName = n } // TableName returns the table name for the host set. @@ -56,12 +46,7 @@ func (s *HostSet) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (s *HostSet) SetTableName(n string) { - switch n { - case "": - s.tableName = defaultHostSetTableName - default: - s.tableName = n - } + s.tableName = n } // TableName returns the table name for the host set. @@ -75,10 +60,5 @@ func (m *HostSetMember) TableName() string { // SetTableName sets the table name. If the caller attempts to // set the name to "" the name will be reset to the default name. func (m *HostSetMember) SetTableName(n string) { - switch n { - case "": - m.tableName = defaultHostSetMemberTableName - default: - m.tableName = n - } + m.tableName = n } diff --git a/internal/iam/auth_account.go b/internal/iam/auth_account.go index 0c7328c2e..552521350 100644 --- a/internal/iam/auth_account.go +++ b/internal/iam/auth_account.go @@ -72,10 +72,5 @@ func (a *AuthAccount) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (a *AuthAccount) SetTableName(n string) { - switch n { - case "": - a.tableName = defaultAuthAccountTableName - default: - a.tableName = n - } + a.tableName = n } diff --git a/internal/iam/group.go b/internal/iam/group.go index 589609024..eae7e9fe1 100644 --- a/internal/iam/group.go +++ b/internal/iam/group.go @@ -99,10 +99,5 @@ func (g *Group) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (g *Group) SetTableName(n string) { - switch n { - case "": - g.tableName = defaultGroupTableName - default: - g.tableName = n - } + g.tableName = n } diff --git a/internal/iam/role.go b/internal/iam/role.go index f272b5dd8..c557e2ebb 100644 --- a/internal/iam/role.go +++ b/internal/iam/role.go @@ -107,10 +107,5 @@ func (r *Role) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (r *Role) SetTableName(n string) { - switch n { - case "": - r.tableName = defaultRoleTableName - default: - r.tableName = n - } + r.tableName = n } diff --git a/internal/iam/role_grant.go b/internal/iam/role_grant.go index 35155a875..f2ca195b8 100644 --- a/internal/iam/role_grant.go +++ b/internal/iam/role_grant.go @@ -102,10 +102,5 @@ func (g *RoleGrant) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (g *RoleGrant) SetTableName(n string) { - switch n { - case "": - g.tableName = defaultRoleGrantTable - default: - g.tableName = n - } + g.tableName = n } diff --git a/internal/iam/scope.go b/internal/iam/scope.go index 713265729..86e80fbd8 100644 --- a/internal/iam/scope.go +++ b/internal/iam/scope.go @@ -201,10 +201,5 @@ func (s *Scope) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (s *Scope) SetTableName(n string) { - switch n { - case "": - s.tableName = defaultScopeTableName - default: - s.tableName = n - } + s.tableName = n } diff --git a/internal/iam/user.go b/internal/iam/user.go index 3bc70aa1c..0b5f7a395 100644 --- a/internal/iam/user.go +++ b/internal/iam/user.go @@ -100,10 +100,5 @@ func (u *User) TableName() string { // interface. If the caller attempts to set the name to "" the name will be // reset to the default name. func (u *User) SetTableName(n string) { - switch n { - case "": - u.tableName = defaultUserTableName - default: - u.tableName = n - } + u.tableName = n } diff --git a/internal/oplog/oplog_test/db.go b/internal/oplog/oplog_test/db.go index 0f6476901..7fad2f8e2 100644 --- a/internal/oplog/oplog_test/db.go +++ b/internal/oplog/oplog_test/db.go @@ -36,12 +36,7 @@ func (u *TestUser) TableName() string { // ReplayableMessage. If the caller attempts to set the name to "" the name will be // reset to the default name. func (u *TestUser) SetTableName(n string) { - switch n { - case "": - u.Table = defaultTestUserTableName - default: - u.Table = n - } + u.Table = n } // TableName overrides the table name for TestCar @@ -54,12 +49,7 @@ func (c *TestCar) TableName() string { // SetTableName allows the table name to be overridden and makes a TestCar a ReplayableMessage func (c *TestCar) SetTableName(n string) { - switch n { - case "": - c.Table = defaultTestCarTableName - default: - c.Table = n - } + c.Table = n } // TableName overrids the table name for TestRental @@ -72,10 +62,5 @@ func (r *TestRental) TableName() string { // SetTableName allows the table name to be overridden and makes a TestRental a ReplayableMessage func (r *TestRental) SetTableName(n string) { - switch n { - case "": - r.Table = defaultTestRentalTableName - default: - r.Table = n - } + r.Table = n }