refactoring

This commit is contained in:
crusader
2017-09-05 16:48:19 +09:00
parent 7b05682732
commit 0cf3116314
12 changed files with 228 additions and 66 deletions

30
grpc/client.go Normal file
View File

@@ -0,0 +1,30 @@
package grpc
import (
"context"
"strings"
oas "git.loafle.net/overflow/overflow_api_server/golang"
)
func Exec(ctx context.Context, method string, params []string) (string, error) {
c, err := _pool.Get()
if nil != err {
}
defer _pool.Put(c)
sm := strings.Split(method, ".")
si := &oas.ServerInput{
Target: sm[0],
Method: sm[1],
Params: params,
}
so, err := c.(oas.OverflowApiServerClient).Exec(ctx, si)
if err != nil {
return "", err
}
return so.Result, nil
}

View File

@@ -5,11 +5,14 @@ import (
"fmt"
"git.loafle.net/commons_go/config"
cgp "git.loafle.net/commons_go/grpc_pool"
"git.loafle.net/commons_go/logging"
ogp "git.loafle.net/overflow/overflow_grpc_pool"
)
func NewPool(ctx context.Context) ogp.Pool {
var _pool cgp.Pool
func InitializePool(ctx context.Context) {
var err error
h := &poolHandlers{
ctx: ctx,
logger: logging.WithContext(ctx),
@@ -18,10 +21,8 @@ func NewPool(ctx context.Context) ogp.Pool {
h.MaxIdle = h.cfg.GetInt("pool.MaxIdle")
h.MaxCapacity = h.cfg.GetInt("pool.MaxCapacity")
p, err := ogp.New(ctx, h)
_pool, err = cgp.New(ctx, h)
if nil != err {
h.logger.Fatal(fmt.Sprintf("GRpc Pool: %v", err))
}
return p
}

View File

@@ -6,13 +6,13 @@ import (
"google.golang.org/grpc"
"git.loafle.net/commons_go/config"
cgp "git.loafle.net/commons_go/grpc_pool"
oas "git.loafle.net/overflow/overflow_api_server/golang"
ogp "git.loafle.net/overflow/overflow_grpc_pool"
"go.uber.org/zap"
)
type poolHandlers struct {
ogp.PoolHandlers
cgp.PoolHandlers
ctx context.Context
logger *zap.Logger
cfg config.Configurator