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
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)
}

View File

@ -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)
}