Skip to content

Commit

Permalink
feat: support define error by proto (douyu#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq authored Feb 6, 2023
1 parent 629fe12 commit 596a4ae
Show file tree
Hide file tree
Showing 17 changed files with 473 additions and 130 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ init:
go install github.com/douyu/jupiter/cmd/jupiter
go install github.com/douyu/jupiter/cmd/protoc-gen-go-echo
go install github.com/douyu/jupiter/cmd/protoc-gen-go-gin
go install github.com/douyu/jupiter/cmd/protoc-gen-go-xerror
go install github.com/go-swagger/go-swagger/cmd/swagger
go install github.com/google/wire/cmd/wire
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
Expand Down
2 changes: 2 additions & 0 deletions api/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ deps:
lint:
ignore:
- vendor
- error/v1

use:
- DEFAULT
- COMMENTS
Expand Down
96 changes: 96 additions & 0 deletions api/error/v1/error.pb.go

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

16 changes: 16 additions & 0 deletions api/error/v1/error.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package error.v1;

import "google/protobuf/descriptor.proto";

option go_package = "github.com/douyu/jupiter-layout/api/error/v1;errorv1";
option java_multiple_files = true;
option java_outer_classname = "ErrorProtoV1";
option java_package = "com.douyu.error.v1";

// Extend the google.protobuf.EnumValueOptions to add a custom option
extend google.protobuf.EnumValueOptions {
// msg is the error message for enum value
string msg = 9527;
}
15 changes: 15 additions & 0 deletions api/error/v1/error.swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"swagger": "2.0",
"info": {
"title": "error/v1/error.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {}
}
142 changes: 142 additions & 0 deletions api/helloworld/v1/error.pb.go

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

18 changes: 18 additions & 0 deletions api/helloworld/v1/error.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package helloworld.v1;

import "error/v1/error.proto";

option go_package = "github.com/douyu/jupiter-layout/api/helloworld/v1;helloworldv1";
option java_multiple_files = true;
option java_outer_classname = "HelloWorldProtoV1";
option java_package = "com.douyu.helloworld.v1";

// Error codes for the helloworld.v1 package.
enum Error {
// ERROR_UNSPECIFIED is the invalid code.
ERROR_UNSPECIFIED = 0;
// ERROR_NAME_EMPTY is the error code for empty name.
ERROR_NAME_EMPTY = 1000 [(error.v1.msg) = "name is empty"];
}
15 changes: 15 additions & 0 deletions api/helloworld/v1/error.swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"swagger": "2.0",
"info": {
"title": "helloworld/v1/error.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {}
}
17 changes: 17 additions & 0 deletions api/helloworld/v1/error_xerror.pb.go

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

Loading

0 comments on commit 596a4ae

Please sign in to comment.