overflow_server_app/external/grpc/client.go

36 lines
707 B
Go
Raw Permalink Normal View History

2017-11-23 08:06:44 +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-26 14:47:55 +00:00
if nil == grpcClient {
2017-11-23 08:06:44 +00:00
return "", fmt.Errorf("App: GRPC Pool is not initialized")
}
2018-03-26 14:47:55 +00:00
// var client interface{}
2017-11-23 08:06:44 +00:00
var err error
2018-03-26 14:47:55 +00:00
// if client, err = grpcPool.Get(); nil != err {
// return "", err
// }
// defer grpcPool.Put(client)
2017-11-23 08:06:44 +00:00
sm := strings.Split(method, ".")
si := &ooas.ServerInput{
Target: sm[0],
Method: sm[1],
Params: params,
}
var so *ooas.ServerOutput
2018-03-26 14:47:55 +00:00
if so, err = grpcClient.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err {
2017-11-23 08:06:44 +00:00
return "", err
}
return so.Result, nil
}