Skip to content

Commit 7547453

Browse files
committed
PCSM-219: Remove unnecessary Viper wrappers
- Remove getPort() wrapper, use viper.GetInt("port") directly - Remove unused GetString, GetInt, GetBool, IsSet wrappers from config/config.go - These wrappers added no value (pure pass-through with no added logic)
1 parent be65433 commit 7547453

File tree

2 files changed

+6
-42
lines changed

2 files changed

+6
-42
lines changed

config/config.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,3 @@ func bindEnvVars() {
6565
// Bulk write option (hidden, internal use)
6666
_ = viper.BindEnv("use-collection-bulk-write", "PCSM_USE_COLLECTION_BULK_WRITE")
6767
}
68-
69-
// GetString returns a string configuration value from Viper.
70-
func GetString(key string) string {
71-
return viper.GetString(key)
72-
}
73-
74-
// GetInt returns an integer configuration value from Viper.
75-
func GetInt(key string) int {
76-
return viper.GetInt(key)
77-
}
78-
79-
// GetBool returns a boolean configuration value from Viper.
80-
func GetBool(key string) bool {
81-
return viper.GetBool(key)
82-
}
83-
84-
// IsSet checks if a configuration key has been set.
85-
func IsSet(key string) bool {
86-
return viper.IsSet(key)
87-
}

main.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var rootCmd = &cobra.Command{
8686
return nil
8787
}
8888

89-
port := getPort()
89+
port := viper.GetInt("port")
9090

9191
// Use Viper to get source/target URIs (supports CLI flags and env vars)
9292
sourceURI := viper.GetString("source")
@@ -147,9 +147,7 @@ var statusCmd = &cobra.Command{
147147
Use: "status",
148148
Short: "Get the status of the replication process",
149149
RunE: func(cmd *cobra.Command, _ []string) error {
150-
port := getPort()
151-
152-
return NewClient(port).Status(cmd.Context())
150+
return NewClient(viper.GetInt("port")).Status(cmd.Context())
153151
},
154152
}
155153

@@ -158,8 +156,6 @@ var startCmd = &cobra.Command{
158156
Use: "start",
159157
Short: "Start Cluster Replication",
160158
RunE: func(cmd *cobra.Command, _ []string) error {
161-
port := getPort()
162-
163159
pauseOnInitialSync, _ := cmd.Flags().GetBool("pause-on-initial-sync")
164160
includeNamespaces, _ := cmd.Flags().GetStringSlice("include-namespaces")
165161
excludeNamespaces, _ := cmd.Flags().GetStringSlice("exclude-namespaces")
@@ -170,7 +166,7 @@ var startCmd = &cobra.Command{
170166
ExcludeNamespaces: excludeNamespaces,
171167
}
172168

173-
return NewClient(port).Start(cmd.Context(), startOptions)
169+
return NewClient(viper.GetInt("port")).Start(cmd.Context(), startOptions)
174170
},
175171
}
176172

@@ -179,15 +175,13 @@ var finalizeCmd = &cobra.Command{
179175
Use: "finalize",
180176
Short: "Finalize Cluster Replication",
181177
RunE: func(cmd *cobra.Command, _ []string) error {
182-
port := getPort()
183-
184178
ignoreHistoryLost, _ := cmd.Flags().GetBool("ignore-history-lost")
185179

186180
finalizeOptions := finalizeRequest{
187181
IgnoreHistoryLost: ignoreHistoryLost,
188182
}
189183

190-
return NewClient(port).Finalize(cmd.Context(), finalizeOptions)
184+
return NewClient(viper.GetInt("port")).Finalize(cmd.Context(), finalizeOptions)
191185
},
192186
}
193187

@@ -196,9 +190,7 @@ var pauseCmd = &cobra.Command{
196190
Use: "pause",
197191
Short: "Pause Cluster Replication",
198192
RunE: func(cmd *cobra.Command, _ []string) error {
199-
port := getPort()
200-
201-
return NewClient(port).Pause(cmd.Context())
193+
return NewClient(viper.GetInt("port")).Pause(cmd.Context())
202194
},
203195
}
204196

@@ -207,15 +199,13 @@ var resumeCmd = &cobra.Command{
207199
Use: "resume",
208200
Short: "Resume Cluster Replication",
209201
RunE: func(cmd *cobra.Command, _ []string) error {
210-
port := getPort()
211-
212202
fromFailure, _ := cmd.Flags().GetBool("from-failure")
213203

214204
resumeOptions := resumeRequest{
215205
FromFailure: fromFailure,
216206
}
217207

218-
return NewClient(port).Resume(cmd.Context(), resumeOptions)
208+
return NewClient(viper.GetInt("port")).Resume(cmd.Context(), resumeOptions)
219209
},
220210
}
221211

@@ -312,12 +302,6 @@ var resetHeartbeatCmd = &cobra.Command{
312302
},
313303
}
314304

315-
// getPort returns the port number from Viper configuration.
316-
// Viper handles precedence: CLI flag > env var (PCSM_PORT) > default.
317-
func getPort() int {
318-
return viper.GetInt("port")
319-
}
320-
321305
func main() {
322306
rootCmd.PersistentFlags().String("log-level", "info", "Log level")
323307
rootCmd.PersistentFlags().Bool("log-json", false, "Output log in JSON format")

0 commit comments

Comments
 (0)