add host flag for goc server

This commit is contained in:
lyyyuna 2021-06-20 21:15:51 +08:00
parent ca58af2865
commit 027d31473c
2 changed files with 5 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"github.com/qiniu/goc/v2/pkg/config"
"github.com/qiniu/goc/v2/pkg/server" "github.com/qiniu/goc/v2/pkg/server"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -17,10 +18,10 @@ var serverCmd = &cobra.Command{
func init() { func init() {
// serverCmd.Flags().IntVarP(&config.GocConfig.Port, "port", "", 7777, "listen port to start a coverage host center") // 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.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) rootCmd.AddCommand(serverCmd)
} }
func serve(cmd *cobra.Command, args []string) { func serve(cmd *cobra.Command, args []string) {
server.RunGocServerUntilExit(8080) server.RunGocServerUntilExit(config.GocConfig.Host)
} }

View File

@ -2,7 +2,6 @@ package server
import ( import (
"net/rpc" "net/rpc"
"strconv"
"sync" "sync"
"time" "time"
@ -35,9 +34,8 @@ type gocCoveredAgent struct {
once sync.Once `json:"-"` // 保护 close(exitCh) 只执行一次 once sync.Once `json:"-"` // 保护 close(exitCh) 只执行一次
} }
func RunGocServerUntilExit(port int) { func RunGocServerUntilExit(host string) {
gs := gocServer{ gs := gocServer{
port: port,
storePath: "", storePath: "",
upgrader: websocket.Upgrader{ upgrader: websocket.Upgrader{
ReadBufferSize: 4096, ReadBufferSize: 4096,
@ -60,5 +58,5 @@ func RunGocServerUntilExit(port int) {
v2.GET("/internal/ws/watchstream", nil) v2.GET("/internal/ws/watchstream", nil)
} }
r.Run(":" + strconv.Itoa(port)) r.Run(host)
} }