diff --git a/cmd/server.go b/cmd/server.go index 3866686..d6d2e40 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -1,6 +1,7 @@ package cmd import ( + "github.com/qiniu/goc/v2/pkg/config" "github.com/qiniu/goc/v2/pkg/server" "github.com/spf13/cobra" ) @@ -17,10 +18,10 @@ var serverCmd = &cobra.Command{ func init() { // serverCmd.Flags().IntVarP(&config.GocConfig.Port, "port", "", 7777, "listen port to start a coverage host center") // serverCmd.Flags().StringVarP(&config.GocConfig.StorePath, "storepath", "", "goc.store", "the file to save all goc server information") - + serverCmd.Flags().StringVarP(&config.GocConfig.Host, "host", "", "0.0.0.0:7777", "specify the host of the goc server") rootCmd.AddCommand(serverCmd) } func serve(cmd *cobra.Command, args []string) { - server.RunGocServerUntilExit(8080) + server.RunGocServerUntilExit(config.GocConfig.Host) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 06bc307..1163bdc 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2,7 +2,6 @@ package server import ( "net/rpc" - "strconv" "sync" "time" @@ -35,9 +34,8 @@ type gocCoveredAgent struct { once sync.Once `json:"-"` // 保护 close(exitCh) 只执行一次 } -func RunGocServerUntilExit(port int) { +func RunGocServerUntilExit(host string) { gs := gocServer{ - port: port, storePath: "", upgrader: websocket.Upgrader{ ReadBufferSize: 4096, @@ -60,5 +58,5 @@ func RunGocServerUntilExit(port int) { v2.GET("/internal/ws/watchstream", nil) } - r.Run(":" + strconv.Itoa(port)) + r.Run(host) }