ing
This commit is contained in:
parent
47a5173720
commit
57ecb91133
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,3 +0,0 @@
|
||||||
// Place your settings in this file to overwrite default and user settings.
|
|
||||||
{
|
|
||||||
}
|
|
53
external/grpc/grpc.go
vendored
Normal file
53
external/grpc/grpc.go
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"git.loafle.net/commons/logging-go"
|
||||||
|
oci "git.loafle.net/overflow/central_api/golang"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
var grpcClient oci.OverflowApiServerClient
|
||||||
|
|
||||||
|
func InitPackage() {
|
||||||
|
conn, err := grpc.Dial("192.168.1.50:50006", grpc.WithInsecure())
|
||||||
|
if nil != err {
|
||||||
|
logging.Logger().Panic(err)
|
||||||
|
}
|
||||||
|
grpcClient = oci.NewOverflowApiServerClient(conn)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func DestroyPackage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var execMtx sync.RWMutex
|
||||||
|
|
||||||
|
func Exec(ctx context.Context, method string, params ...string) (string, error) {
|
||||||
|
if nil == grpcClient {
|
||||||
|
return "", fmt.Errorf("GRPC Client is not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
sm := strings.Split(method, ".")
|
||||||
|
si := &oci.ServerInput{
|
||||||
|
Target: sm[0],
|
||||||
|
Method: sm[1],
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
execMtx.Lock()
|
||||||
|
defer execMtx.Unlock()
|
||||||
|
so, err := grpcClient.(oci.OverflowApiServerClient).Exec(ctx, si)
|
||||||
|
if nil != err {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return so.Result, nil
|
||||||
|
}
|
6
glide.yaml
Normal file
6
glide.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package: git.loafle.net/overflow/gateway
|
||||||
|
import:
|
||||||
|
- package: git.loafle.net/overflow/central_api
|
||||||
|
- package: git.loafle.net/commons/logging-go
|
||||||
|
- package: google.golang.org/grpc
|
||||||
|
version: ^1.11.2
|
Loading…
Reference in New Issue
Block a user