Skip to content

Commit 99a9075

Browse files
authored
fixed: optimize the local operation mode and add custom agentport and center server (#228)
1 parent 712fea2 commit 99a9075

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cmd/run.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/qiniu/goc/pkg/cover"
2727
log "github.com/sirupsen/logrus"
2828
"github.com/spf13/cobra"
29+
"github.com/spf13/viper"
2930
)
3031

3132
var runCmd = &cobra.Command{
@@ -53,7 +54,7 @@ goc run . [--buildflags] [--exec] [--arguments]
5354
server := cover.NewMemoryBasedServer() // only save services in memory
5455

5556
// start goc server
56-
var l = newLocalListener()
57+
var l = newLocalListener(agentPort.String())
5758
go func() {
5859
err = server.Route(ioutil.Discard).RunListener(l)
5960
if err != nil {
@@ -63,6 +64,10 @@ goc run . [--buildflags] [--exec] [--arguments]
6364
gocServer := fmt.Sprintf("http://%s", l.Addr().String())
6465
fmt.Printf("[goc] goc server started: %s \n", gocServer)
6566

67+
if viper.IsSet("center") {
68+
gocServer = center
69+
}
70+
6671
// execute covers for the target source with original buildFlags and new GOPATH( tmp:original )
6772
ci := &cover.CoverInfo{
6873
Args: buildFlags,
@@ -93,8 +98,11 @@ func init() {
9398
rootCmd.AddCommand(runCmd)
9499
}
95100

96-
func newLocalListener() net.Listener {
97-
l, err := net.Listen("tcp", "127.0.0.1:0")
101+
func newLocalListener(addr string) net.Listener {
102+
if addr == "" {
103+
addr = "127.0.0.1:0"
104+
}
105+
l, err := net.Listen("tcp", addr)
98106
if err != nil {
99107
if l, err = net.Listen("tcp6", "[::1]:0"); err != nil {
100108
log.Fatalf("failed to listen on a port: %v", err)

0 commit comments

Comments
 (0)