Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

temp #93

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/protoc-gen-go-errorx/gen/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gen

import "github.com/RyoJerryYu/protoc-gen-pluginx/pkg/pluginutils"

type Options struct {
}

type Generator struct {
Options
pluginutils.GenerateOptions
}

func (g *Generator) ApplyTemplate() error {
return nil
}
42 changes: 42 additions & 0 deletions cmd/protoc-gen-go-errorx/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"flag"

"github.com/RyoJerryYu/protoc-gen-pluginx/cmd/protoc-gen-go-errorx/gen"
"github.com/RyoJerryYu/protoc-gen-pluginx/pkg/pluginutils"
"github.com/RyoJerryYu/protoc-gen-pluginx/pkg/version"
"github.com/golang/glog"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)

var options gen.Options

func init() {

}

func main() {
flag.Parse()
defer glog.Flush()

pluginutils.NewForEachFileRunner(pluginutils.PluginInfo{
PluginName: "protoc-gen-go-errorx",
VersionStr: version.Version,
GenFileSuffix: ".pb.errorx.go",
SupportedFeatures: uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL),
}).ForEachFileThat(func(protoFile *protogen.File) bool {
if len(protoFile.Messages) == 0 {
glog.V(1).Infof("Skipping %s, no messages", protoFile.Desc.Path())
return false
}
return true
}).Run(func(genOpt pluginutils.GenerateOptions) error {
g := gen.Generator{
Options: options,
GenerateOptions: genOpt,
}
return g.ApplyTemplate()
})
}
244 changes: 244 additions & 0 deletions proto/ryojerryyu/annotations/errorx.pb.go

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

28 changes: 28 additions & 0 deletions proto/ryojerryyu/annotations/errorx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package ryojerryyu.annotations;

import "google/protobuf/descriptor.proto";
import "google/rpc/code.proto";

option go_package = "github.com/RyoJerryYu/protoc-gen-pluginx/proto/ryojerryyu/annotations";

extend google.protobuf.EnumOptions {
// errorx_is_code is a enum level option to indicate that this enum is an error code
optional bool errorx_is_code = 52013;
}

extend google.protobuf.EnumValueOptions {
// code describes the gRPC status code for this error code
// when using with grpc-gateway, http status code will be defined by this code
optional google.rpc.Code errorx_code = 52014;
}

extend google.protobuf.MessageOptions {
// errorx is a message level option to indicate that this message is an error message
optional bool errorx_is_error = 51015;
}

extend google.protobuf.OneofOptions {
// errorx is a oneof level option to indicate that this oneof is an error oneof
optional bool errorx_is_payload = 52016;
}
20 changes: 20 additions & 0 deletions tests/protoc-gen-go-errorx/common/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v2
inputs:
- directory: .
exclude_paths:
- "ryojerryyu/annotations/fieldmask.proto"
- "ryojerryyu/annotations/errorx.proto"
managed:
enabled: true
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
plugins:
- local: protoc-gen-go
out: .
opt:
- paths=source_relative
# - local: protoc-gen-go-errorx
# out: .
# opt:
# - paths=source_relative
6 changes: 6 additions & 0 deletions tests/protoc-gen-go-errorx/common/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/googleapis/googleapis
commit: e93e34f48be043dab55be31b4b47f458
digest: b5:cebe5dfac5f7d67c55296f37ad9d368dba8d9862777e69d5d99eb1d72dc95fa68cd6323b483ca42cf70e66060002c1bc36e1f5f754b217a5c771c108eb243dbf
4 changes: 4 additions & 0 deletions tests/protoc-gen-go-errorx/common/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v2
name: buf.build/tests/protoc-gen-pluginx
deps:
- buf.build/googleapis/googleapis
3 changes: 3 additions & 0 deletions tests/protoc-gen-go-errorx/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package common

//go:generate buf generate
Loading
Loading