shared project

This commit is contained in:
geek 2017-05-23 19:08:51 +09:00
commit e87f23cd22
5 changed files with 375 additions and 0 deletions

61
.gitignore vendored Normal file
View 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/

3
grpc/cmd Normal file
View File

@ -0,0 +1,3 @@
protoc -I/usr/local/include -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I grpc/ grpc/grpc.proto --go_out=plugins=grpc:grpc
protoc -I/usr/local/include -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I grpc/ grpc/grpc.proto --grpc-gateway_out=logtostderr=true:grpc

176
grpc/grpc.pb.go Normal file
View File

@ -0,0 +1,176 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: grpc.proto
/*
Package gwrpc is a generated protocol buffer package.
It is generated from these files:
grpc.proto
It has these top-level messages:
ServiceInput
ServiceOutput
*/
package gwrpc
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "google.golang.org/genproto/googleapis/api/annotations"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type ServiceInput struct {
ServiceName string `protobuf:"bytes,1,opt,name=serviceName" json:"serviceName,omitempty"`
MethodName string `protobuf:"bytes,2,opt,name=methodName" json:"methodName,omitempty"`
Param map[string]string `protobuf:"bytes,3,rep,name=param" json:"param,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
}
func (m *ServiceInput) Reset() { *m = ServiceInput{} }
func (m *ServiceInput) String() string { return proto.CompactTextString(m) }
func (*ServiceInput) ProtoMessage() {}
func (*ServiceInput) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *ServiceInput) GetServiceName() string {
if m != nil {
return m.ServiceName
}
return ""
}
func (m *ServiceInput) GetMethodName() string {
if m != nil {
return m.MethodName
}
return ""
}
func (m *ServiceInput) GetParam() map[string]string {
if m != nil {
return m.Param
}
return nil
}
type ServiceOutput struct {
}
func (m *ServiceOutput) Reset() { *m = ServiceOutput{} }
func (m *ServiceOutput) String() string { return proto.CompactTextString(m) }
func (*ServiceOutput) ProtoMessage() {}
func (*ServiceOutput) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func init() {
proto.RegisterType((*ServiceInput)(nil), "gwrpc.ServiceInput")
proto.RegisterType((*ServiceOutput)(nil), "gwrpc.ServiceOutput")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for OverflowGateway service
type OverflowGatewayClient interface {
ExecServices(ctx context.Context, in *ServiceInput, opts ...grpc.CallOption) (*ServiceOutput, error)
}
type overflowGatewayClient struct {
cc *grpc.ClientConn
}
func NewOverflowGatewayClient(cc *grpc.ClientConn) OverflowGatewayClient {
return &overflowGatewayClient{cc}
}
func (c *overflowGatewayClient) ExecServices(ctx context.Context, in *ServiceInput, opts ...grpc.CallOption) (*ServiceOutput, error) {
out := new(ServiceOutput)
err := grpc.Invoke(ctx, "/gwrpc.OverflowGateway/ExecServices", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for OverflowGateway service
type OverflowGatewayServer interface {
ExecServices(context.Context, *ServiceInput) (*ServiceOutput, error)
}
func RegisterOverflowGatewayServer(s *grpc.Server, srv OverflowGatewayServer) {
s.RegisterService(&_OverflowGateway_serviceDesc, srv)
}
func _OverflowGateway_ExecServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ServiceInput)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(OverflowGatewayServer).ExecServices(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/gwrpc.OverflowGateway/ExecServices",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(OverflowGatewayServer).ExecServices(ctx, req.(*ServiceInput))
}
return interceptor(ctx, in, info, handler)
}
var _OverflowGateway_serviceDesc = grpc.ServiceDesc{
ServiceName: "gwrpc.OverflowGateway",
HandlerType: (*OverflowGatewayServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ExecServices",
Handler: _OverflowGateway_ExecServices_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "grpc.proto",
}
func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 274 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4a, 0x2f, 0x2a, 0x48,
0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4d, 0x2f, 0x2f, 0x2a, 0x48, 0x96, 0x92, 0x49,
0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0xd5, 0x4f, 0x2c, 0xc8, 0xd4, 0x4f, 0xcc, 0xcb, 0xcb, 0x2f, 0x49,
0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0x86, 0x28, 0x52, 0x3a, 0xc0, 0xc8, 0xc5, 0x13, 0x9c, 0x5a, 0x54,
0x96, 0x99, 0x9c, 0xea, 0x99, 0x57, 0x50, 0x5a, 0x22, 0xa4, 0xc0, 0xc5, 0x5d, 0x0c, 0xe1, 0xfb,
0x25, 0xe6, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x0b, 0x09, 0xc9, 0x71, 0x71,
0xe5, 0xa6, 0x96, 0x64, 0xe4, 0xa7, 0x80, 0x15, 0x30, 0x81, 0x15, 0x20, 0x89, 0x08, 0x99, 0x70,
0xb1, 0x16, 0x24, 0x16, 0x25, 0xe6, 0x4a, 0x30, 0x2b, 0x30, 0x6b, 0x70, 0x1b, 0xc9, 0xe9, 0x81,
0xdd, 0xa1, 0x87, 0x6c, 0x8b, 0x5e, 0x00, 0x48, 0x81, 0x6b, 0x5e, 0x49, 0x51, 0x65, 0x10, 0x44,
0xb1, 0x94, 0x05, 0x17, 0x17, 0x42, 0x50, 0x48, 0x80, 0x8b, 0x39, 0x3b, 0xb5, 0x12, 0x6a, 0x3b,
0x88, 0x29, 0x24, 0xc2, 0xc5, 0x5a, 0x96, 0x98, 0x53, 0x0a, 0xb3, 0x10, 0xc2, 0xb1, 0x62, 0xb2,
0x60, 0x54, 0xe2, 0xe7, 0xe2, 0x85, 0x9a, 0xed, 0x5f, 0x5a, 0x52, 0x50, 0x5a, 0x62, 0x94, 0xc7,
0xc5, 0xef, 0x5f, 0x96, 0x5a, 0x94, 0x96, 0x93, 0x5f, 0xee, 0x9e, 0x58, 0x92, 0x5a, 0x9e, 0x58,
0x29, 0x14, 0xcd, 0xc5, 0xe3, 0x5a, 0x91, 0x9a, 0x0c, 0x55, 0x57, 0x2c, 0x24, 0x8c, 0xc5, 0x51,
0x52, 0x22, 0xa8, 0x82, 0x10, 0xd3, 0x94, 0x14, 0x9a, 0x2e, 0x3f, 0x99, 0xcc, 0x24, 0xa5, 0x24,
0xaa, 0x5f, 0x66, 0xa8, 0x9f, 0x0f, 0x35, 0x57, 0x1f, 0x1a, 0x20, 0xc5, 0x56, 0x8c, 0x5a, 0x49,
0x6c, 0xe0, 0xa0, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x61, 0x13, 0xf7, 0x0f, 0x7d, 0x01,
0x00, 0x00,
}

112
grpc/grpc.pb.gw.go Normal file
View File

@ -0,0 +1,112 @@
// Code generated by protoc-gen-grpc-gateway
// source: grpc.proto
// DO NOT EDIT!
/*
Package gwrpc is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package gwrpc
import (
"io"
"net/http"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
)
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
func request_OverflowGateway_ExecServices_0(ctx context.Context, marshaler runtime.Marshaler, client OverflowGatewayClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ServiceInput
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.ExecServices(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
// RegisterOverflowGatewayHandlerFromEndpoint is same as RegisterOverflowGatewayHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterOverflowGatewayHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterOverflowGatewayHandler(ctx, mux, conn)
}
// RegisterOverflowGatewayHandler registers the http handlers for service OverflowGateway to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterOverflowGatewayHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
client := NewOverflowGatewayClient(conn)
mux.Handle("POST", pattern_OverflowGateway_ExecServices_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
}
resp, md, err := request_OverflowGateway_ExecServices_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_OverflowGateway_ExecServices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_OverflowGateway_ExecServices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "overflow", "services"}, ""))
)
var (
forward_OverflowGateway_ExecServices_0 = runtime.ForwardResponseMessage
)

23
grpc/grpc.proto Normal file
View File

@ -0,0 +1,23 @@
syntax = "proto3";
package gwrpc;
import "google/api/annotations.proto";
message ServiceInput {
string serviceName = 1;
string methodName = 2;
map<string,string> param = 3;
}
message ServiceOutput {
}
service OverflowGateway {
rpc ExecServices(ServiceInput) returns (ServiceOutput) {
option (google.api.http) = {
post: "/v1/overflow/services"
body: "*"
};
}
}