From 7f8edaa2670bd6107c6696e53139f56d8d224d4d Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 6 Apr 2018 21:23:53 +0900 Subject: [PATCH] project init --- external/grpc/client.go | 54 ---------------------------------------- server/server-handler.go | 24 ++++++++++++++---- 2 files changed, 19 insertions(+), 59 deletions(-) delete mode 100644 external/grpc/client.go diff --git a/external/grpc/client.go b/external/grpc/client.go deleted file mode 100644 index 8462d65..0000000 --- a/external/grpc/client.go +++ /dev/null @@ -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) - -} \ No newline at end of file diff --git a/server/server-handler.go b/server/server-handler.go index 8b55914..f754709 100644 --- a/server/server-handler.go +++ b/server/server-handler.go @@ -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) +} \ No newline at end of file