From 175b040f67b256245618eb2c8420d524465ec4f0 Mon Sep 17 00:00:00 2001 From: ehco1996 Date: Wed, 28 Aug 2019 17:20:27 +0800 Subject: [PATCH] fix SyncTask --- cli/main.go | 2 +- tasks.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cli/main.go b/cli/main.go index 3a7a66f..4785279 100644 --- a/cli/main.go +++ b/cli/main.go @@ -10,7 +10,7 @@ import ( "github.com/Ehco1996/v2scar" ) -var SYNC_TIME = 60 +var SYNC_TIME int func main() { diff --git a/tasks.go b/tasks.go index 12c9a60..25ae5fe 100644 --- a/tasks.go +++ b/tasks.go @@ -11,8 +11,8 @@ import ( v2stats "v2ray.com/core/app/stats/command" ) -var API_ENDPOINT = "127.0.0.1:8080" -var GRPC_ENDPOINT = "http://fun.com/api" +var API_ENDPOINT string +var GRPC_ENDPOINT string type UserConfig struct { UserId int `json:"user_id"` @@ -43,10 +43,12 @@ func SyncTask(up *UserPool) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() conn, err := grpc.DialContext(ctx, GRPC_ENDPOINT, grpc.WithInsecure(), grpc.WithBlock()) - defer conn.Close() + if err != nil { log.Printf("[WARNING]: GRPC连接失败,请检查V2ray是否运行并开放对应grpc端口 当前GRPC地址: %v", GRPC_ENDPOINT) return + } else { + defer conn.Close() } // Init Client @@ -66,7 +68,6 @@ func SyncTask(up *UserPool) { // sync user traffic syncUserTrafficToServer(up, statClient, httpClient) - } func initOrUpdateUser(up *UserPool, c v2proxyman.HandlerServiceClient, sr *syncResp) {