From df4f9465fc4595f71ea5d47148e25b7545255cba Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 22 Mar 2018 22:55:19 +0900 Subject: [PATCH] ing --- external/grpc/client.go | 16 +++++----- external/grpc/pool.go | 70 ++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/external/grpc/client.go b/external/grpc/client.go index d6f6b78..9733c58 100644 --- a/external/grpc/client.go +++ b/external/grpc/client.go @@ -9,16 +9,16 @@ import ( ) func Exec(ctx context.Context, method string, params []string) (string, error) { - if nil == grpcPool { - return "", fmt.Errorf("App: GRPC Pool is not initialized") + if nil == grpcClient { + return "", fmt.Errorf("App: GRPC Client is not initialized") } - var client interface{} + // var client interface{} var err error - if client, err = grpcPool.Get(); nil != err { - return "", err - } - defer grpcPool.Put(client) + // if client, err = grpcPool.Get(); nil != err { + // return "", err + // } + // defer grpcPool.Put(client) sm := strings.Split(method, ".") si := &ooas.ServerInput{ @@ -27,7 +27,7 @@ func Exec(ctx context.Context, method string, params []string) (string, error) { Params: params, } var so *ooas.ServerOutput - if so, err = client.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err { + if so, err = grpcClient.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err { return "", err } diff --git a/external/grpc/pool.go b/external/grpc/pool.go index dd335e9..c944825 100644 --- a/external/grpc/pool.go +++ b/external/grpc/pool.go @@ -1,47 +1,61 @@ package grpc import ( - cgp "git.loafle.net/commons_go/grpc_pool" "git.loafle.net/commons_go/logging" ooas "git.loafle.net/overflow/overflow_api_server/golang" "git.loafle.net/overflow/overflow_gateway_websocket/config" "google.golang.org/grpc" ) -var grpcPool cgp.Pool +var grpcClient ooas.OverflowApiServerClient func ExternalInit() { - ph := &grpcPoolHandlers{} - ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity - ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle - ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout - ph.Wait = config.Config.GRPC.Pool.Wait - - grpcPool = cgp.New(ph) - - if err := grpcPool.Start(); nil != err { - logging.Logger().Panicf("App: %v", err) - return + conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure()) + if nil != err { + logging.Logger().Panic(err) } + grpcClient = ooas.NewOverflowApiServerClient(conn) + } func ExternalDestroy() { - if nil != grpcPool { - grpcPool.Stop() - } + } -type grpcPoolHandlers struct { - cgp.PoolHandlers -} +// var grpcPool cgp.Pool -func (h *grpcPoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) { - var err error - conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure()) - if nil != err { - return nil, nil, err - } - c := ooas.NewOverflowApiServerClient(conn) +// func ExternalInit() { +// ph := &grpcPoolHandlers{} +// ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity +// ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle +// ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout +// ph.Wait = config.Config.GRPC.Pool.Wait - return conn, c, nil -} +// grpcPool = cgp.New(ph) + +// if err := grpcPool.Start(); nil != err { +// logging.Logger().Panicf("App: %v", err) +// return +// } +// } + +// func ExternalDestroy() { +// if nil != grpcPool { +// grpcPool.Stop() +// } +// } + +// type grpcPoolHandlers struct { +// cgp.PoolHandlers +// } + +// func (h *grpcPoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) { +// var err error +// conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure()) +// if nil != err { +// return nil, nil, err +// } +// c := ooas.NewOverflowApiServerClient(conn) + +// return conn, c, nil +// }