overflow_gateway_websocket/external/grpc/client.go
crusader 5f10acb5e9 ing
2018-03-22 22:57:27 +09:00

43 lines
774 B
Go

package grpc
import (
"context"
"fmt"
"strings"
"sync"
ooas "git.loafle.net/overflow/overflow_api_server/golang"
)
var execMtx sync.RWMutex
func Exec(ctx context.Context, method string, params []string) (string, error) {
if nil == grpcClient {
return "", fmt.Errorf("App: GRPC Client is not initialized")
}
// var client interface{}
var err error
// if client, err = grpcPool.Get(); nil != err {
// return "", err
// }
// defer grpcPool.Put(client)
sm := strings.Split(method, ".")
si := &ooas.ServerInput{
Target: sm[0],
Method: sm[1],
Params: params,
}
execMtx.RLock()
so, err := grpcClient.(ooas.OverflowApiServerClient).Exec(ctx, si)
if nil != err {
execMtx.RUnlock()
return "", err
}
execMtx.RUnlock()
return so.Result, nil
}