Skip to content

Commit

Permalink
finish grpc structure
Browse files Browse the repository at this point in the history
  • Loading branch information
cjp2600 committed Apr 23, 2020
1 parent d55c444 commit 43ac221
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 325 deletions.
254 changes: 22 additions & 232 deletions Gopkg.lock

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,9 @@
name = "github.com/grpc-ecosystem/go-grpc-middleware"
version = "1.2.0"

[[constraint]]
name = "github.com/grpc-ecosystem/go-grpc-prometheus"
version = "1.2.0"

[[constraint]]
name = "github.com/grpc-ecosystem/grpc-gateway"
version = "1.14.3"

[[constraint]]
name = "github.com/mailru/easyjson"
version = "0.7.1"
version = "1.14.4"

[[constraint]]
name = "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -77,17 +69,13 @@
branch = "master"
name = "github.com/yalp/jsonpath"

[[constraint]]
name = "gitlab.com/pharmpixel/pharmpixel"
version = "202004.22.0"

[[constraint]]
branch = "master"
name = "google.golang.org/genproto"

[[constraint]]
name = "google.golang.org/grpc"
version = "1.28.1"
version = "1.29.0"

[[constraint]]
branch = "v2"
Expand Down
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
build:
protoc -I. \
-I$(GOPATH)/src \
-I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--plugin=protoc-gen-mongo=$(GOPATH)/bin/protoc-gen-bom \
--mongo_out="generateCrud=true,gateway:." \
proto/gol.proto

protoc -I. \
-I$(GOPATH)/src \
-I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
Expand Down
8 changes: 4 additions & 4 deletions cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ func (h *Handler) CustomHTTPError(ctx context.Context, _ *runtime.ServeMux, mars
}

func (h *Handler) Execute(c context.Context, request *pb.ExecuteRequest) (*pb.ExecuteResponse, error) {
var response *pb.ExecuteResponse
var jobs map[string]interface{}
var response pb.ExecuteResponse
var j []floc.Job

ctx := floc.NewContext()
jobs = make(map[string]interface{})
jobs := make(map[string]string)
for _, sequence := range request.Sequence {
switch sequence.Type {
case pb.SequenceType_parallel:
Expand Down Expand Up @@ -83,5 +82,6 @@ func (h *Handler) Execute(c context.Context, request *pb.ExecuteRequest) (*pb.Ex
}
}
}
return response, nil
response.Jobs = jobs
return &response, nil
}
9 changes: 0 additions & 9 deletions cmd/helper.go

This file was deleted.

16 changes: 12 additions & 4 deletions cmd/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,19 @@ func (r *RequestTranslator) Execute(ctx floc.Context) (*resty.Response, error) {
req.EnableTrace()

if r.Job.Body != nil {
req.SetBody(r.Job.Body)
ub, err := r.Job.GetUnmarshalBody()
if err != nil {
return nil, err
}
req.SetBody(ub)
}
if r.Job.Header != nil {
ub, err := r.Job.GetUnmarshalHeader()
if err != nil {
return nil, err
}
req.SetHeaders(ub)
}
/* if r.Job.Header != nil {
req.SetHeaders(r.Job.GetHeaders(ctx))
}*/
switch r.Job.Method {
case pb.Methods_get:
response, err = req.Get(r.Job.GetUrl())
Expand Down
70 changes: 70 additions & 0 deletions core/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package core

import (
"fmt"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/golang/protobuf/ptypes/wrappers"
"strings"
)

func GetAnyType(a *any.Any) (interface{}, error) {
switch strings.ToLower(a.TypeUrl) {
case strings.ToLower("google.protobuf.StringValue"):
var md wrappers.StringValue
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.BytesValue"):
var md wrappers.BytesValue
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.BoolValue"):
var md wrappers.BoolValue
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return &md.Value, nil
case strings.ToLower("google.protobuf.UInt32Value"):
var md wrappers.UInt32Value
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.Int32Value"):
var md wrappers.Int32Value
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.UInt64Value"):
var md wrappers.UInt64Value
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.Int64Value"):
var md wrappers.Int64Value
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.FloatValue"):
var md wrappers.FloatValue
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
case strings.ToLower("google.protobuf.DoubleValue"):
var md wrappers.DoubleValue
if err := ptypes.UnmarshalAny(a, &md); err != nil {
return nil, err
}
return md.Value, nil
}

return nil, fmt.Errorf("use google.protobuf types list")
}
110 changes: 63 additions & 47 deletions proto/gol.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions proto/gol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ service Gol {
}

message ExecuteResponse {

map<string, string> jobs = 1;
}

message ExecuteRequest {
Expand All @@ -24,7 +24,7 @@ message ExecuteRequest {

message Sequence {
SequenceType type = 1;
repeated Job Jobs = 2;
repeated Job jobs = 2;
}

enum Methods {
Expand All @@ -43,8 +43,8 @@ message Job {
string id = 1;
string url = 2;
Methods method = 3;
google.protobuf.Any body = 4;
google.protobuf.Any header = 5;
map<string, google.protobuf.Any> body = 4;
map<string, google.protobuf.Any> header = 5;
repeated Var var = 6;
}

Expand Down
Loading

0 comments on commit 43ac221

Please sign in to comment.