shared project
This commit is contained in:
commit
7e600dc44e
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# 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/
|
||||||
|
|
48
gateway/services.go
Normal file
48
gateway/services.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package gateway
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
pb "loafle.com/overflow/overflow_api_service/grpc"
|
||||||
|
"loafle.com/overflow/overflow_proxy_service/proxy"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"reflect"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var g_services map[string]interface{}
|
||||||
|
|
||||||
|
func AddServices(name string, s interface{}) {
|
||||||
|
if g_services == nil {
|
||||||
|
g_services = make(map[string]interface{},0)
|
||||||
|
}
|
||||||
|
|
||||||
|
g_services[name] = s
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitServices() {
|
||||||
|
g_services = make(map[string]interface{},0)
|
||||||
|
|
||||||
|
// proxy services save
|
||||||
|
AddServices("Member", proxy.NewMember())
|
||||||
|
}
|
||||||
|
type ServiceImpl struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb.ServiceOutput, error) {
|
||||||
|
// Todo Check Service Name
|
||||||
|
serviceName, ok := g_services[in.ServiceName]
|
||||||
|
|
||||||
|
log.Println(serviceName)
|
||||||
|
if !ok {
|
||||||
|
glog.Error("Not Exist Service Name")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo Param Unmarshal
|
||||||
|
|
||||||
|
// Todo Getting a structure by service name
|
||||||
|
|
||||||
|
// Todo Call Service Method
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
41
gwrpc_service.go
Normal file
41
gwrpc_service.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
pb "loafle.com/overflow/overflow_api_service/grpc"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
overflowEndpoint = flag.String("echo_endpoint", "localhost:9090", "/v1/overflow/services")
|
||||||
|
)
|
||||||
|
|
||||||
|
func runGwRpc() (err error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
mux := runtime.NewServeMux()
|
||||||
|
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||||
|
|
||||||
|
err = pb.RegisterOverflowGatewayHandlerFromEndpoint(ctx, mux, *overflowEndpoint, opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.ListenAndServe(":8080", mux)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
defer glog.Flush()
|
||||||
|
|
||||||
|
if err := runGwRpc(); err != nil {
|
||||||
|
glog.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
36
rpc_service.go
Normal file
36
rpc_service.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"flag"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
pb "loafle.com/overflow/overflow_api_service/grpc"
|
||||||
|
"loafle.com/overflow/overflow_gateway_service/gateway"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runRpc() error {
|
||||||
|
l, err := net.Listen("tcp", ":9090")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s := grpc.NewServer()
|
||||||
|
|
||||||
|
pb.RegisterOverflowGatewayServer(s, &gateway.ServiceImpl{})
|
||||||
|
s.Serve(l)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
defer glog.Flush()
|
||||||
|
|
||||||
|
gateway.InitServices()
|
||||||
|
|
||||||
|
if err := runRpc(); err != nil {
|
||||||
|
glog.Fatal("Gateway Server Failed: ", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user