project init

This commit is contained in:
geek 2018-04-06 21:23:53 +09:00
parent a1463ed091
commit 7f8edaa267
2 changed files with 19 additions and 59 deletions

View File

@ -1,54 +0,0 @@
package grpc
import (
"sync"
"fmt"
"strings"
"context"
"git.loafle.net/commons/logging-go"
ocag "git.loafle.net/overflow/central_api/golang"
"google.golang.org/grpc"
)
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 := &ocag.ServerInput{
Target: sm[0],
Method: sm[1],
Params: params,
}
execMtx.RLock()
so, err := grpcClient.(ocag.OverflowApiServerClient).Exec(ctx, si)
if nil != err {
execMtx.RUnlock()
return "", err
}
execMtx.RUnlock()
return so.Result, nil
}
var grpcClient ocag.OverflowApiServerClient
func ExternalInit() {
conn, err := grpc.Dial("192.168.1.50:50006", grpc.WithInsecure())
if nil != err {
logging.Logger().Panic(err)
}
grpcClient = ocag.NewOverflowApiServerClient(conn)
}

View File

@ -2,19 +2,27 @@ package server
import (
cssw "git.loafle.net/commons/server-go/socket/web"
csgw "git.loafle.net/commons/server-go/socket/web"
"git.loafle.net/commons/server-go"
"net"
"git.loafle.net/overflow/gateway_rpc/external/grpc"
ogeg "git.loafle.net/overflow/gateway/external/grpc"
)
type ServerHandler interface {
csgw.ServerHandler
}
type ServerHandlers struct {
cssw.ServerHandlers
csgw.ServerHandlers
}
func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error {
grpc.ExternalInit()
return sh.Init(serverCtx)
if err := sh.ServerHandlers.Init(serverCtx); nil != err {
return nil
}
ogeg.InitPackage()
return nil
}
func (sh *ServerHandlers) Listener(serverCtx server.ServerCtx) (net.Listener, error) {
@ -25,3 +33,9 @@ func (sh *ServerHandlers) Listener(serverCtx server.ServerCtx) (net.Listener, er
return l, nil
}
func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) {
ogeg.DestroyPackage()
sh.ServerHandlers.Destroy(serverCtx)
}