overflow_gateway_websocket/external/grpc/client.go

36 lines
709 B
Go
Raw Normal View History

2017-11-10 13:24:10 +00:00
package grpc
import (
"context"
"fmt"
"strings"
ooas "git.loafle.net/overflow/overflow_api_server/golang"
)
func Exec(ctx context.Context, method string, params []string) (string, error) {
2018-03-22 13:55:19 +00:00
if nil == grpcClient {
return "", fmt.Errorf("App: GRPC Client is not initialized")
2017-11-10 13:24:10 +00:00
}
2018-03-22 13:55:19 +00:00
// var client interface{}
2017-11-10 13:24:10 +00:00
var err error
2018-03-22 13:55:19 +00:00
// if client, err = grpcPool.Get(); nil != err {
// return "", err
// }
// defer grpcPool.Put(client)
2017-11-10 13:24:10 +00:00
sm := strings.Split(method, ".")
si := &ooas.ServerInput{
Target: sm[0],
Method: sm[1],
Params: params,
}
var so *ooas.ServerOutput
2018-03-22 13:55:19 +00:00
if so, err = grpcClient.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err {
2017-11-10 13:24:10 +00:00
return "", err
}
return so.Result, nil
}