Skip to content

Commit 1b0b6e7

Browse files
committed
fix: update to buf
1 parent 96f8d80 commit 1b0b6e7

26 files changed

+320
-2357
lines changed

Makefile

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
SHELL:=/usr/bin/env bash
22

33
.DEFAULT_GOAL:=help
4+
COLOR := "\e[1;36m%s\e[0m"
5+
6+
# Note this is just for the tour!
7+
export BUF_USER=yusank
48

59
##################################################
610
# Development #
@@ -26,15 +30,8 @@ test: ## Run test against code.
2630

2731
##@ Generate
2832

29-
.PHONY: gen-protoc
30-
gen-protoc: ## Run protoc command to generate pb code.
31-
# call gen_proto.sh
32-
./gen_proto.sh
33-
3433
.PHONY: protoc
3534

36-
COLOR := "\e[1;36m%s\e[0m"
37-
3835
PROTO_ROOT := .
3936
PROTO_IGNORE := ./third_party
4037
PROTO_FILES = $(shell find $(PROTO_ROOT) -path $(PROTO_IGNORE) -prune -o -type f -name "*.proto" -print)
@@ -59,6 +56,12 @@ protoc: ## Generate pb code.
5956
tools-install: ## Install tools.
6057
go get -u github.com/golang/protobuf/protoc-gen-go
6158

59+
.PHONY: buf
60+
buf: ## run buf generate command.
61+
@printf $(COLOR) "Generating buf code..."
62+
buf generate
63+
@printf $(COLOR) "Done."
64+
6265
##################################################
6366
# General #
6467
##################################################

buf.gen.tag.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: v1
2+
plugins:
3+
- name: gotag
4+
out: .
5+
opt: paths=source_relative,auto="form-as-snake"

buf.gen.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: v1
2+
plugins:
3+
- name: go
4+
out: .
5+
opt: paths=source_relative
6+
- name: go-grpc
7+
out: .
8+
opt: paths=source_relative
9+
- name: validate
10+
out: .
11+
opt:
12+
- lang=go
13+
- paths=source_relative

buf.lock

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v1
3+
deps:
4+
- remote: buf.build
5+
owner: envoyproxy
6+
repository: protoc-gen-validate
7+
commit: dc09a417d27241f7b069feae2cd74a0e

buf.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: v1
2+
deps:
3+
- buf.build/envoyproxy/protoc-gen-validate
4+
breaking:
5+
use:
6+
- FILE
7+
lint:
8+
use:
9+
- DEFAULT

config/registry/v1/registry.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/registry/v1/registry.proto

+42-25
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,57 @@
11
syntax = "proto3";
22

33
package api.config.registry.v1;
4-
option go_package = "github.com/go-goim/api/config/registry/v1";
54

65
import "google/protobuf/duration.proto";
7-
86
import "validate/validate.proto";
97

8+
option go_package = "github.com/go-goim/api/config/registry/v1";
9+
1010
message RegistryInfo {
11-
repeated string addr = 1 [(validate.rules).repeated = {
12-
min_items: 1,
13-
unique: true,
14-
}];
15-
string scheme = 2 [(validate.rules).string = {in: ["http", "grpc"]}];
16-
// range [10ms, 10s]
17-
google.protobuf.Duration dial_timeout_sec = 3 [(validate.rules).duration = {
18-
gte: {nanos: 1000000, seconds: 0},
19-
lte: {seconds: 10}
20-
}];
21-
google.protobuf.Duration dial_keep_alive_time_sec = 4;
22-
google.protobuf.Duration dial_keep_alive_timeout_sec = 5;
11+
repeated string addr = 1 [(validate.rules).repeated = {
12+
min_items: 1,
13+
unique: true,
14+
}];
15+
string scheme = 2 [(validate.rules).string = {
16+
in: [
17+
"http",
18+
"grpc"
19+
]
20+
}];
21+
// range [10ms, 10s]
22+
google.protobuf.Duration dial_timeout_sec = 3 [(validate.rules).duration = {
23+
gte: {
24+
nanos: 1000000,
25+
seconds: 0
26+
},
27+
lte: {
28+
seconds: 10
29+
}
30+
}];
31+
google.protobuf.Duration dial_keep_alive_time_sec = 4;
32+
google.protobuf.Duration dial_keep_alive_timeout_sec = 5;
2333
}
2434

2535
message ConfigCenterInfo {
26-
// PathPrefix is prefix key of config center.
27-
string path_prefix = 1;
28-
// Paths is config paths of config center.
29-
repeated string paths = 2 [(validate.rules).repeated = {unique: true}];
30-
// Format is config format of config center.
31-
string format = 3 [(validate.rules).string = {in: ["json", "yaml"]}];
36+
// PathPrefix is prefix key of config center.
37+
string path_prefix = 1;
38+
// Paths is config paths of config center.
39+
repeated string paths = 2 [(validate.rules).repeated = {
40+
unique: true
41+
}];
42+
// Format is config format of config center.
43+
string format = 3 [(validate.rules).string = {
44+
in: [
45+
"json",
46+
"yaml"
47+
]
48+
}];
3249
}
3350

3451
message Registry {
35-
ConfigCenterInfo config_center = 1;
36-
oneof reg {
37-
RegistryInfo consul = 2;
38-
RegistryInfo etcd = 3;
39-
}
52+
ConfigCenterInfo config_center = 1;
53+
oneof reg {
54+
RegistryInfo consul = 2;
55+
RegistryInfo etcd = 3;
56+
}
4057
}

config/v1/config.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/v1/config.proto

+111-73
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,137 @@
11
syntax = "proto3";
22

33
package api.config.v1;
4-
option go_package = "github.com/go-goim/api/config/v1";
54

65
import "google/protobuf/duration.proto";
7-
86
import "validate/validate.proto";
97

8+
option go_package = "github.com/go-goim/api/config/v1";
9+
1010
message Server {
11-
string scheme = 1 [(validate.rules).string = {in: ["http", "grpc", "tcp"]}];
12-
int32 port = 2 [(validate.rules).int32 = {gt: 10000, lt: 60535}];
13-
// range:[10ms, 10s]
14-
google.protobuf.Duration timeout = 3 [(validate.rules).duration = {
15-
gte: {nanos: 10000000, seconds: 0},
16-
lte: {seconds: 10}
17-
}];
11+
string scheme = 1 [(validate.rules).string = {
12+
in: [
13+
"http",
14+
"grpc",
15+
"tcp"
16+
]
17+
}];
18+
int32 port = 2 [(validate.rules).int32 = {
19+
gt: 10000,
20+
lt: 60535
21+
}];
22+
// range:[10ms, 10s]
23+
google.protobuf.Duration timeout = 3 [(validate.rules).duration = {
24+
gte: {
25+
nanos: 10000000,
26+
seconds: 0
27+
},
28+
lte: {
29+
seconds: 10
30+
}
31+
}];
1832
}
1933

2034
message Service {
21-
// name has three parts:
22-
// 1. constant value: "goim"
23-
// 2. service type: ["service", "worker", "admin"]
24-
// 3. service name: any string
25-
// parts joined by "."
26-
// example: "goim.service.chat"
27-
string name = 1 [(validate.rules).string = {pattern: "^goim\\.(service|worker|admin)\\.[a-zA-Z0-9_]+$"}];
28-
// version must match like "vx.y.z"
29-
string version = 2 [(validate.rules).string = {pattern: "^v[0-9]+\\.[0-9]+\\.[0-9]+$"}];
30-
optional Server http = 3;
31-
optional Server grpc = 4;
32-
Log log = 5;
33-
map<string, string> metadata = 6;
34-
Redis redis = 7;
35-
MQ mq = 8;
36-
MySQL mysql = 9;
37-
// services name
38-
string gatewayService = 10;
39-
string userService = 11;
40-
string pushService = 12;
41-
string storeWorker = 13;
42-
string msgService = 14;
43-
string msgWorker = 15;
35+
// name has three parts:
36+
// 1. constant value: "goim"
37+
// 2. service type: ["service", "worker", "admin"]
38+
// 3. service name: any string
39+
// parts joined by "."
40+
// example: "goim.service.chat"
41+
string name = 1 [(validate.rules).string = {
42+
pattern: "^goim\\.(service|worker|admin)\\.[a-zA-Z0-9_]+$"
43+
}];
44+
// version must match like "vx.y.z"
45+
string version = 2 [(validate.rules).string = {
46+
pattern: "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
47+
}];
48+
optional Server http = 3;
49+
optional Server grpc = 4;
50+
Log log = 5;
51+
map<string, string> metadata = 6;
52+
Redis redis = 7;
53+
MQ mq = 8;
54+
MySQL mysql = 9;
55+
// services name
56+
string gatewayService = 10;
57+
string userService = 11;
58+
string pushService = 12;
59+
string storeWorker = 13;
60+
string msgService = 14;
61+
string msgWorker = 15;
4462
}
4563

4664
enum Level {
47-
DEBUG = 0;
48-
INFO = 1;
49-
WARNING = 2;
50-
ERROR = 3;
51-
FATAL = 4;
65+
DEBUG = 0;
66+
INFO = 1;
67+
WARNING = 2;
68+
ERROR = 3;
69+
FATAL = 4;
5270
}
5371

5472
message Log {
55-
optional string log_path = 1;
56-
Level level = 2 [(validate.rules).enum.defined_only = true];
57-
bool enable_console = 3;
73+
optional string log_path = 1;
74+
Level level = 2 [(validate.rules).enum.defined_only = true];
75+
bool enable_console = 3;
5876
}
5977

6078
message Redis {
61-
string addr = 1;
62-
string password = 2;
63-
int32 max_conns = 3;
64-
int32 min_idle_conns = 4;
65-
// range: [10ms,10s]
66-
google.protobuf.Duration dial_timeout = 5 [(validate.rules).duration = {
67-
gte: {nanos: 10000000, seconds: 0},
68-
lte: {seconds: 10}
69-
}];
70-
// range: [10ms,10s]
71-
google.protobuf.Duration idle_timeout = 6 [(validate.rules).duration = {
72-
gte: {nanos: 10000000, seconds: 0},
73-
lte: {seconds: 10}
74-
}];
79+
string addr = 1;
80+
string password = 2;
81+
int32 max_conns = 3;
82+
int32 min_idle_conns = 4;
83+
// range: [10ms,10s]
84+
google.protobuf.Duration dial_timeout = 5 [(validate.rules).duration = {
85+
gte: {
86+
nanos: 10000000,
87+
seconds: 0
88+
},
89+
lte: {
90+
seconds: 10
91+
}
92+
}];
93+
// range: [10ms,10s]
94+
google.protobuf.Duration idle_timeout = 6 [(validate.rules).duration = {
95+
gte: {
96+
nanos: 10000000,
97+
seconds: 0
98+
},
99+
lte: {
100+
seconds: 10
101+
}
102+
}];
75103
}
76104

77105
message MQ {
78-
repeated string addr = 1;
79-
int32 max_retry = 2;
106+
repeated string addr = 1;
107+
int32 max_retry = 2;
80108
}
81109

82110
message MySQL {
83-
string addr = 1;
84-
string user = 2;
85-
string password = 3;
86-
string db = 4;
87-
int32 max_idle_conns = 5;
88-
int32 max_open_conns = 6;
89-
// range: [10ms,10s]
90-
google.protobuf.Duration idle_timeout = 7 [(validate.rules).duration = {
91-
gte: {nanos: 1000000, seconds: 0},
92-
lte: {seconds: 10}
93-
}];
94-
// range: [10ms,10s]
95-
google.protobuf.Duration open_timeout = 8 [(validate.rules).duration = {
96-
gte: {nanos: 1000000, seconds: 0},
97-
lte: {seconds: 10}
98-
}];
99-
}
111+
string addr = 1;
112+
string user = 2;
113+
string password = 3;
114+
string db = 4;
115+
int32 max_idle_conns = 5;
116+
int32 max_open_conns = 6;
117+
// range: [10ms,10s]
118+
google.protobuf.Duration idle_timeout = 7 [(validate.rules).duration = {
119+
gte: {
120+
nanos: 1000000,
121+
seconds: 0
122+
},
123+
lte: {
124+
seconds: 10
125+
}
126+
}];
127+
// range: [10ms,10s]
128+
google.protobuf.Duration open_timeout = 8 [(validate.rules).duration = {
129+
gte: {
130+
nanos: 1000000,
131+
seconds: 0
132+
},
133+
lte: {
134+
seconds: 10
135+
}
136+
}];
137+
}

0 commit comments

Comments
 (0)