43 lines
774 B
Go
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
|
|
}
|