Ver Fonte

添加超时功能处理

fancl há 1 ano atrás
pai
commit
5dac511cae
1 ficheiros alterados com 10 adições e 1 exclusões
  1. 10 1
      entry/cli/client.go

+ 10 - 1
entry/cli/client.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"git.nspix.com/golang/kos/util/env"
 	"github.com/peterh/liner"
 	"io"
 	"math"
@@ -240,14 +241,22 @@ func (client *Client) Close() (err error) {
 }
 
 func NewClient(ctx context.Context, addr string) *Client {
+	var (
+		err     error
+		timeout time.Duration
+	)
 	if ctx == nil {
 		ctx = context.Background()
 	}
+	duration := env.Get("VOX_TIMEOUT", "30s")
+	if timeout, err = time.ParseDuration(duration); err != nil {
+		timeout = time.Second * 30
+	}
 	return &Client{
 		ctx:           ctx,
 		address:       addr,
 		name:          filepath.Base(os.Args[0]),
-		Timeout:       time.Second * 30,
+		Timeout:       timeout,
 		liner:         liner.NewLiner(),
 		readyChan:     make(chan struct{}, 1),
 		exitChan:      make(chan struct{}),