Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Buf proto generation (#85)
Browse files Browse the repository at this point in the history
buf build proto generating
  • Loading branch information
vitiko authored Jan 31, 2022
1 parent 94b5791 commit 20be829
Show file tree
Hide file tree
Showing 114 changed files with 7,656 additions and 4,683 deletions.
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GOFLAGS ?= -mod=vendor

PROTO_PACKAGES_GO := examples/cpaper_extended/schema state/schema examples/cpaper_asservice/schema
PROTO_PACKAGES_CCGW := extensions/debug extensions/owner examples/cpaper_asservice/service
PROTO_PACKAGES_GO := state
PROTO_PACKAGES_GW := gateway
PROTO_PACKAGES_CC := extensions examples

test:
@echo "go test -mod vendor ./..."
Expand All @@ -14,9 +15,10 @@ refresh-deps:
@GOFLAGS='' GONOSUMDB=github.com/hyperledger/fabric go mod vendor

proto:
@for pkg in $(PROTO_PACKAGES_GO) ;do echo $$pkg && buf generate --template buf.gen.go.yaml --path $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done
@for pkg in $(PROTO_PACKAGES_CCGW) ;do echo $$pkg && buf generate --template buf.gen.gw.yaml --path $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done

@for pkg in $(PROTO_PACKAGES_CC) ;do echo $$pkg && buf generate --template buf.gen.cc.yaml $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done
@for pkg in $(PROTO_PACKAGES_GW) ;do echo $$pkg && buf generate --template buf.gen.gw.yaml $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done
@for pkg in $(PROTO_PACKAGES_GO) ;do echo $$pkg && buf generate --template buf.gen.go.yaml $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done
clean:
@for pkg in $(PROTO_PACKAGES_GO); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.cc.go' -or -name '*.pb.gw.go' -or -name '*.swagger.json' \) -delete;done
@for pkg in $(PROTO_PACKAGES_CCGW); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.cc.go' -or -name '*.pb.gw.go' -or -name '*.swagger.json' \) -delete;done
@for pkg in $(PROTO_PACKAGES_CC); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.cc.go' -or -name '*.pb.gw.go' -or -name '*.swagger.json' -or -name '*.pb.md' \) -delete;done
@for pkg in $(PROTO_PACKAGES_GW); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.gw.go' -or -name '*.swagger.json' -or -name '*.pb.md' \) -delete;done
@for pkg in $(PROTO_PACKAGES_GO); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.md' \) -delete;done
40 changes: 34 additions & 6 deletions buf.gen.cc.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
# The version of the generation template.
# Required.
# The only currently-valid value is v1beta1.
version: v1beta1
version: v1

# The plugins to run.
plugins:

- name: go
out: .
opt:
- plugins=grpc
- paths=source_relative

- name: govalidators
out: .
opt:
- paths=source_relative

- name: grpc-gateway
out: .
opt:
- logtostderr=true
- paths=source_relative

- name: swagger
out: .
opt:
- logtostderr=true

- name: cc-gateway
out: .
out: .
opt:
- logtostderr=true
- paths=source_relative

- name: doc
out: .
opt:
- markdown,doc.pb.md,source_relative

14 changes: 8 additions & 6 deletions buf.gen.go.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# The version of the generation template.
# Required.
# The only currently-valid value is v1beta1.
version: v1beta1
version: v1

# The plugins to run.
plugins:

- name: go
out: .
opt:
Expand All @@ -14,4 +11,9 @@ plugins:
- name: govalidators
out: .
opt:
- paths=source_relative
- paths=source_relative

- name: doc
out: .
opt:
- markdown,doc.pb.md:.
59 changes: 6 additions & 53 deletions buf.gen.gw.yaml
Original file line number Diff line number Diff line change
@@ -1,77 +1,30 @@
# The version of the generation template.
# Required.
# The only currently-valid value is v1beta1.
version: v1beta1

version: v1

plugins:

- name: go
out: .

# Any options to provide to the plugin.
# Optional.
# Can be either a single string or list of strings.
opt:
- plugins=grpc
- paths=source_relative

# The custom path to the plugin binary, if not protoc-gen-NAME on your $PATH.
#path: custom-gen-go # optional

# The generation strategy to use. There are two options:
#
# 1. "directory"
#
# This will result in buf splitting the input files by directory, and making separate plugin
# invocations in parallel. This is roughly the concurrent equivalent of:
#
# for dir in $(find . -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq); do
# protoc -I . $(find "${dir}" -name '*.proto')
# done
#
# Almost every Protobuf plugin either requires this, or works with this,
# and this is the recommended and default value.
#
# 2. "all"
#
# This will result in buf making a single plugin invocation with all input files.
# This is roughly the equivalent of:
#
# protoc -I . $(find . -name '*.proto')
#
# This is needed for certain plugins that expect all files to be given at once.
#
# Optional. If omitted, "directory" is used. Most users should not need to set this option.

# - name: go-grpc
# out: .
# opt:
# - paths=source_relative
- name: govalidators
out: .
opt:
- paths=source_relative

- name: openapiv2
out: .
opt:
- logtostderr=true

- name: grpc-gateway
out: .
opt:
- logtostderr=true
- paths=source_relative

- name: cc-gateway
- name: swagger
out: .
opt:
- logtostderr=true
- paths=source_relative

## TODO specify doc correct out params
# - name: doc
# out: .
# opt:
# - markdown,doc.md
- name: doc
out: .
opt:
- markdown,doc.pb.md,source_relative
7 changes: 7 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
directories:
- examples
- extensions
- gateway
- state
- third_party
30 changes: 0 additions & 30 deletions buf.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions examples/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1
lint:
use:
- BASIC
- FILE_LOWER_SNAKE_CASE
- SERVICE_SUFFIX
- ENUM_VALUE_PREFIX
except:
- PACKAGE_DIRECTORY_MATCH

breaking:
use:
- FILE
17 changes: 9 additions & 8 deletions examples/cpaper_asservice/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
.: generate

generate:
@protoc --version
@echo "commercial paper schema proto generation"
@protoc -I=./schema/ \
-I=../../vendor \
--go_out=./schema/ \
--govalidators_out=./schema/ \
--doc_out=./schema/ --doc_opt=markdown,schema.md \
./schema/schema.proto
# @protoc --version
# @echo "commercial paper schema proto generation"
# @protoc -I=./schema/ \
# -I=../../vendor \
# --go_out=./schema/ \
# --govalidators_out=./schema/ \
# --doc_out=./schema/ --doc_opt=markdown,schema.md \
# ./schema/schema.proto

@echo "commercial paper service proto generation"
@protoc -I=./service/ \
-I=./schema/ \
-I=../../../../../ \
-I=../../vendor \
-I=../../third_party/googleapis \
Expand Down
7 changes: 3 additions & 4 deletions examples/cpaper_asservice/bin/api/mock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"google.golang.org/grpc"

"github.com/s7techlab/cckit/examples/cpaper_asservice"
cpaperservice "github.com/s7techlab/cckit/examples/cpaper_asservice/service"
"github.com/s7techlab/cckit/gateway"
"github.com/s7techlab/cckit/testing"
)
Expand Down Expand Up @@ -50,7 +49,7 @@ func main() {
log.Fatalln(err)
}
// Generated gateway for access to chaincode from external application
cpaperGateway := cpaperservice.NewCPaperGateway(
cpaperGateway := cpaper_asservice.NewCPaperServiceGateway(
cpaperMockService, // gateway use mocked chaincode access service
channelName,
chaincodeName,
Expand All @@ -63,7 +62,7 @@ func main() {

// Create gRPC server
s := grpc.NewServer()
cpaperservice.RegisterCPaperServer(s, cpaperGateway)
cpaper_asservice.RegisterCPaperServiceServer(s, cpaperGateway)

// Runs gRPC server in goroutine
go func() {
Expand All @@ -79,7 +78,7 @@ func main() {
// Register gRPC server endpoint
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
err = cpaperservice.RegisterCPaperHandlerFromEndpoint(ctx, mux, grpcAddress, opts)
err = cpaper_asservice.RegisterCPaperServiceHandlerFromEndpoint(ctx, mux, grpcAddress, opts)
if err != nil {
log.Fatalf("failed to register handler from endpoint %v", err)
}
Expand Down
5 changes: 1 addition & 4 deletions examples/cpaper_asservice/chaincode.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cpaper_asservice

//go:generate make

import (
"github.com/s7techlab/cckit/examples/cpaper_asservice/service"
"github.com/s7techlab/cckit/extensions/encryption"
"github.com/s7techlab/cckit/extensions/owner"
"github.com/s7techlab/cckit/router"
Expand All @@ -14,7 +11,7 @@ func CCRouter(name string) (*router.Group, error) {
// Store on the ledger the information about chaincode instantiation
r.Init(owner.InvokeSetFromCreator)

if err := service.RegisterCPaperChaincode(r, &service.CPaperImpl{}); err != nil {
if err := RegisterCPaperServiceChaincode(r, &CPaperService{}); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 20be829

Please sign in to comment.