commit a1463ed09198e4af0c4e2fd34d39538b1c70c11b Author: geek Date: Fri Apr 6 20:57:54 2018 +0900 project init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3733e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Go template +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ +.idea/ +*.iml + +vendor/ +glide.lock +.DS_Store +dist/ +debug diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2ca2b1d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug", + "type": "go", + "request": "launch", + "mode": "debug", + "remotePath": "", + "port": 2345, + "host": "127.0.0.1", + "program": "${workspaceRoot}/main.go", + "env": {}, + "args": [], + "showLog": true + }, + { + "name": "File Debug", + "type": "go", + "request": "launch", + "mode": "debug", + "remotePath": "", + "port": 2345, + "host": "127.0.0.1", + "program": "${fileDirname}", + "env": {}, + "args": [], + "showLog": true + } + + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..20af2f6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +// Place your settings in this file to overwrite default and user settings. +{ +} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..d353bb4 --- /dev/null +++ b/config.json @@ -0,0 +1,29 @@ +{ + "websocket": { + "handshakeTimeout": 0, + "readBufferSize": 8192, + "writeBufferSize": 8192, + "enableCompression": false + }, + "gRPC": { + "addr": "192.168.1.50:50006", + "tls": false, + "pool": { + "maxIdle": 1, + "maxCapacity": 3, + "idleTimeout": 240, + "wait": false + } + }, + "redis": { + "network": "tcp", + "addr": "192.168.1.50:6379", + "tls": false, + "pool": { + "maxIdle": 1, + "maxCapacity": 3, + "idleTimeout": 240, + "wait": false + } + } +} \ No newline at end of file diff --git a/external/grpc/client.go b/external/grpc/client.go new file mode 100644 index 0000000..8462d65 --- /dev/null +++ b/external/grpc/client.go @@ -0,0 +1,54 @@ +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 new file mode 100644 index 0000000..8b55914 --- /dev/null +++ b/server/server-handler.go @@ -0,0 +1,27 @@ +package server + + +import ( + cssw "git.loafle.net/commons/server-go/socket/web" + "git.loafle.net/commons/server-go" + "net" + "git.loafle.net/overflow/gateway_rpc/external/grpc" +) + +type ServerHandlers struct { + cssw.ServerHandlers +} + +func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error { + grpc.ExternalInit() + return sh.Init(serverCtx) +} + +func (sh *ServerHandlers) Listener(serverCtx server.ServerCtx) (net.Listener, error) { + l, err := net.Listen("tcp", "192.168.1.103:44449") + if nil != err { + return nil, err + } + + return l, nil +}