From 26dcae43bb9a257db2f36e66badb3123c0c31fb1 Mon Sep 17 00:00:00 2001 From: xige-16 Date: Thu, 18 Jul 2024 12:53:07 +0800 Subject: [PATCH] Configurable server port (#380) Signed-off-by: xige-16 --- cmd/server.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/server.go b/cmd/server.go index f427b222..c910ba57 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -3,12 +3,19 @@ package cmd import ( "context" "fmt" + "os" + "strconv" "github.com/spf13/cobra" "github.com/zilliztech/milvus-backup/core" "github.com/zilliztech/milvus-backup/core/paramtable" ) +const ( + DefaultServerPort = "8080" + ServerPortEnvKey = "SERVER_PORT" +) + var ( port string ) @@ -34,7 +41,12 @@ var serverCmd = &cobra.Command{ } func init() { - serverCmd.Flags().StringVarP(&port, "port", "p", "8080", "Port to listen") + serverPort := os.Getenv(ServerPortEnvKey) + _, err := strconv.Atoi(serverPort) + if err != nil { + serverPort = DefaultServerPort + } + serverCmd.Flags().StringVarP(&port, "port", "p", serverPort, "Port to listen") rootCmd.AddCommand(serverCmd) }