Skip to content

Commit

Permalink
Configurable server port (#380)
Browse files Browse the repository at this point in the history
Signed-off-by: xige-16 <xige2016@gmail.com>
  • Loading branch information
xige-16 authored Jul 18, 2024
1 parent 0d6fd2b commit 26dcae4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
}

0 comments on commit 26dcae4

Please sign in to comment.