overflow_proxy_service/proxy/service.go

38 lines
678 B
Go
Raw Normal View History

package proxy
import (
"log"
2017-05-29 11:39:56 +00:00
pb "git.loafle.net/overflow/overflow_api_db/build/golang"
"google.golang.org/grpc"
"golang.org/x/net/context"
2017-06-08 08:34:21 +00:00
)
2017-06-08 11:53:04 +00:00
func InvokeDB(targetDb, methodName string, param map[string]string) (string, error) {
in := &pb.DBInput{}
in.TargetDao = targetDb
in.Method = methodName
in.Param = param
2017-06-08 01:46:29 +00:00
conn, err := grpc.Dial(":50006", grpc.WithInsecure())
if err != nil {
2017-06-08 11:53:04 +00:00
//log.Fatal("Rpc Error: ", err)
return "", err
}
defer conn.Close()
client := pb.NewDBClient(conn)
out, err := client.Exec(context.Background(), in)
if err != nil {
2017-06-08 11:53:04 +00:00
//log.Fatal("Rpc Client Error: ", err)
return "", err
}
log.Print(out)
2017-06-08 11:53:04 +00:00
return out.Result, nil
2017-06-08 02:21:48 +00:00
}