Skip to content

Commit

Permalink
refactor proto
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed Sep 10, 2023
1 parent 5b9dd88 commit 2b7ac77
Show file tree
Hide file tree
Showing 30 changed files with 6,010 additions and 508 deletions.
16 changes: 11 additions & 5 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pink = printf "\x1b[35m\#\# %s\x1b[0m\n" $1
cyan = printf "\x1b[36m\#\# %s\x1b[0m\n" $1

define go-install
GO111MODULE=on go install $1@latest
GO111MODULE=on go install \
-mod=readonly \
$1@latest
endef

define mkdir
Expand All @@ -31,12 +33,16 @@ endef
define proto-code-gen
protoc \
$(PROTO_PATHS:%=-I %) \
--go_out=$(GOPATH)/src --plugin protoc-gen-go="$(GOBIN)/protoc-gen-go" \
--go-vtproto_out=$(GOPATH)/src --plugin protoc-gen-go-vtproto="$(GOBIN)/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=grpc+marshal+unmarshal+size+equal+clone \
--go_out=$(GOPATH)/src \
--plugin protoc-gen-go="$(GOBIN)/protoc-gen-go" \
--go-vtproto_out=$(GOPATH)/src \
--plugin protoc-gen-go-vtproto="$(GOBIN)/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=grpc+marshal+unmarshal+size+equal+clone+pool \
--go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
$1
endef
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
# --go-grpc_out=$(GOPATH)/src \
# --plugin protoc-gen-go-grpc="${GOBIN}/protoc-gen-go-grpc" \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Insert.MultiRequest \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Insert.Request \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
Expand Down
31 changes: 30 additions & 1 deletion Makefile.d/proto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,30 @@ proto/deps: \
$(GOPATH)/src/github.com/planetscale/vtprotobuf \
$(GOPATH)/src/github.com/protocolbuffers/protobuf \
$(GOPATH)/src/google.golang.org/genproto \
$(GOPATH)/src/google.golang.org/protobuf
$(GOPATH)/src/google.golang.org/protobuf \
$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto

.PHONY: proto/clean/deps
## uninstall all protobuf dependencies
proto/clean/deps:
rm -rf $(GOBIN)/protoc-gen-doc \
$(GOBIN)/protoc-gen-go \
$(GOBIN)/protoc-gen-go-grpc \
$(GOBIN)/protoc-gen-go-vtproto \
$(GOBIN)/protoc-gen-grpc-gateway \
$(GOBIN)/protoc-gen-swagger \
$(GOBIN)/protoc-gen-validate \
$(GOBIN)/prototool \
$(GOBIN)/swagger \
$(GOPATH)/src/github.com/envoyproxy/protoc-gen-validate \
$(GOPATH)/src/github.com/golang/protobuf \
$(GOPATH)/src/github.com/googleapis/googleapis \
$(GOPATH)/src/github.com/planetscale/vtprotobuf \
$(GOPATH)/src/github.com/protocolbuffers/protobuf \
$(GOPATH)/src/google.golang.org/genproto \
$(GOPATH)/src/google.golang.org/protobuf \
$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto


$(GOPATH)/src/github.com/protocolbuffers/protobuf:
git clone \
Expand Down Expand Up @@ -129,6 +152,12 @@ $(GOBIN)/protoc-gen-go-vtproto:
$(GOBIN)/swagger:
$(call go-install, github.com/go-swagger/go-swagger/cmd/swagger)

$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto:
curl -fsSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/error_details.proto -o $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s/package google.rpc/package rpc.v1/" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s%google.golang.org/genproto/googleapis/rpc/errdetails;errdetails%github.com/vdaas/vald/apis/grpc/v1/rpc/errdetails%" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s/com.google.rpc/org.vdaas.vald.api.v1.rpc/" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto

$(PBGOS): \
$(PROTOS) \
proto/deps
Expand Down
313 changes: 288 additions & 25 deletions apis/docs/v1/docs.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apis/grpc/v1/filter/egress/egress_filter_vtproto.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *filterClient) FilterDistance(ctx context.Context, in *payload.Object_Di
}

func (c *filterClient) FilterVector(ctx context.Context, in *payload.Object_Vector, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.egress.v1.Filter/FilterVector", in, out, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -127,7 +127,7 @@ func _Filter_FilterDistance_Handler(srv interface{}, ctx context.Context, dec fu
}

func _Filter_FilterVector_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(payload.Object_Vector)
in := payload.Object_VectorFromVTPool()
if err := dec(in); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions apis/grpc/v1/filter/ingress/ingress_filter_vtproto.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewFilterClient(cc grpc.ClientConnInterface) FilterClient {
}

func (c *filterClient) GenVector(ctx context.Context, in *payload.Object_Blob, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.ingress.v1.Filter/GenVector", in, out, opts...)
if err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (c *filterClient) GenVector(ctx context.Context, in *payload.Object_Blob, o
}

func (c *filterClient) FilterVector(ctx context.Context, in *payload.Object_Vector, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.ingress.v1.Filter/FilterVector", in, out, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -127,7 +127,7 @@ func _Filter_GenVector_Handler(srv interface{}, ctx context.Context, dec func(in
}

func _Filter_FilterVector_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(payload.Object_Vector)
in := payload.Object_VectorFromVTPool()
if err := dec(in); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2b7ac77

Please sign in to comment.