Skip to content

Commit

Permalink
fix: update to buf
Browse files Browse the repository at this point in the history
  • Loading branch information
yusank committed Jun 28, 2022
1 parent 96f8d80 commit 1b0b6e7
Show file tree
Hide file tree
Showing 26 changed files with 320 additions and 2,357 deletions.
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
SHELL:=/usr/bin/env bash

.DEFAULT_GOAL:=help
COLOR := "\e[1;36m%s\e[0m"

# Note this is just for the tour!
export BUF_USER=yusank

##################################################
# Development #
Expand All @@ -26,15 +30,8 @@ test: ## Run test against code.

##@ Generate

.PHONY: gen-protoc
gen-protoc: ## Run protoc command to generate pb code.
# call gen_proto.sh
./gen_proto.sh

.PHONY: protoc

COLOR := "\e[1;36m%s\e[0m"

PROTO_ROOT := .
PROTO_IGNORE := ./third_party
PROTO_FILES = $(shell find $(PROTO_ROOT) -path $(PROTO_IGNORE) -prune -o -type f -name "*.proto" -print)
Expand All @@ -59,6 +56,12 @@ protoc: ## Generate pb code.
tools-install: ## Install tools.
go get -u github.com/golang/protobuf/protoc-gen-go

.PHONY: buf
buf: ## run buf generate command.
@printf $(COLOR) "Generating buf code..."
buf generate
@printf $(COLOR) "Done."

##################################################
# General #
##################################################
Expand Down
5 changes: 5 additions & 0 deletions buf.gen.tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v1
plugins:
- name: gotag
out: .
opt: paths=source_relative,auto="form-as-snake"
13 changes: 13 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1
plugins:
- name: go
out: .
opt: paths=source_relative
- name: go-grpc
out: .
opt: paths=source_relative
- name: validate
out: .
opt:
- lang=go
- paths=source_relative
7 changes: 7 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: envoyproxy
repository: protoc-gen-validate
commit: dc09a417d27241f7b069feae2cd74a0e
9 changes: 9 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1
deps:
- buf.build/envoyproxy/protoc-gen-validate
breaking:
use:
- FILE
lint:
use:
- DEFAULT
2 changes: 1 addition & 1 deletion config/registry/v1/registry.pb.go

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

67 changes: 42 additions & 25 deletions config/registry/v1/registry.proto
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
syntax = "proto3";

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

import "google/protobuf/duration.proto";

import "validate/validate.proto";

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

message RegistryInfo {
repeated string addr = 1 [(validate.rules).repeated = {
min_items: 1,
unique: true,
}];
string scheme = 2 [(validate.rules).string = {in: ["http", "grpc"]}];
// range [10ms, 10s]
google.protobuf.Duration dial_timeout_sec = 3 [(validate.rules).duration = {
gte: {nanos: 1000000, seconds: 0},
lte: {seconds: 10}
}];
google.protobuf.Duration dial_keep_alive_time_sec = 4;
google.protobuf.Duration dial_keep_alive_timeout_sec = 5;
repeated string addr = 1 [(validate.rules).repeated = {
min_items: 1,
unique: true,
}];
string scheme = 2 [(validate.rules).string = {
in: [
"http",
"grpc"
]
}];
// range [10ms, 10s]
google.protobuf.Duration dial_timeout_sec = 3 [(validate.rules).duration = {
gte: {
nanos: 1000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
google.protobuf.Duration dial_keep_alive_time_sec = 4;
google.protobuf.Duration dial_keep_alive_timeout_sec = 5;
}

message ConfigCenterInfo {
// PathPrefix is prefix key of config center.
string path_prefix = 1;
// Paths is config paths of config center.
repeated string paths = 2 [(validate.rules).repeated = {unique: true}];
// Format is config format of config center.
string format = 3 [(validate.rules).string = {in: ["json", "yaml"]}];
// PathPrefix is prefix key of config center.
string path_prefix = 1;
// Paths is config paths of config center.
repeated string paths = 2 [(validate.rules).repeated = {
unique: true
}];
// Format is config format of config center.
string format = 3 [(validate.rules).string = {
in: [
"json",
"yaml"
]
}];
}

message Registry {
ConfigCenterInfo config_center = 1;
oneof reg {
RegistryInfo consul = 2;
RegistryInfo etcd = 3;
}
ConfigCenterInfo config_center = 1;
oneof reg {
RegistryInfo consul = 2;
RegistryInfo etcd = 3;
}
}
2 changes: 1 addition & 1 deletion config/v1/config.pb.go

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

184 changes: 111 additions & 73 deletions config/v1/config.proto
Original file line number Diff line number Diff line change
@@ -1,99 +1,137 @@
syntax = "proto3";

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

import "google/protobuf/duration.proto";

import "validate/validate.proto";

option go_package = "github.com/go-goim/api/config/v1";

message Server {
string scheme = 1 [(validate.rules).string = {in: ["http", "grpc", "tcp"]}];
int32 port = 2 [(validate.rules).int32 = {gt: 10000, lt: 60535}];
// range:[10ms, 10s]
google.protobuf.Duration timeout = 3 [(validate.rules).duration = {
gte: {nanos: 10000000, seconds: 0},
lte: {seconds: 10}
}];
string scheme = 1 [(validate.rules).string = {
in: [
"http",
"grpc",
"tcp"
]
}];
int32 port = 2 [(validate.rules).int32 = {
gt: 10000,
lt: 60535
}];
// range:[10ms, 10s]
google.protobuf.Duration timeout = 3 [(validate.rules).duration = {
gte: {
nanos: 10000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
}

message Service {
// name has three parts:
// 1. constant value: "goim"
// 2. service type: ["service", "worker", "admin"]
// 3. service name: any string
// parts joined by "."
// example: "goim.service.chat"
string name = 1 [(validate.rules).string = {pattern: "^goim\\.(service|worker|admin)\\.[a-zA-Z0-9_]+$"}];
// version must match like "vx.y.z"
string version = 2 [(validate.rules).string = {pattern: "^v[0-9]+\\.[0-9]+\\.[0-9]+$"}];
optional Server http = 3;
optional Server grpc = 4;
Log log = 5;
map<string, string> metadata = 6;
Redis redis = 7;
MQ mq = 8;
MySQL mysql = 9;
// services name
string gatewayService = 10;
string userService = 11;
string pushService = 12;
string storeWorker = 13;
string msgService = 14;
string msgWorker = 15;
// name has three parts:
// 1. constant value: "goim"
// 2. service type: ["service", "worker", "admin"]
// 3. service name: any string
// parts joined by "."
// example: "goim.service.chat"
string name = 1 [(validate.rules).string = {
pattern: "^goim\\.(service|worker|admin)\\.[a-zA-Z0-9_]+$"
}];
// version must match like "vx.y.z"
string version = 2 [(validate.rules).string = {
pattern: "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
}];
optional Server http = 3;
optional Server grpc = 4;
Log log = 5;
map<string, string> metadata = 6;
Redis redis = 7;
MQ mq = 8;
MySQL mysql = 9;
// services name
string gatewayService = 10;
string userService = 11;
string pushService = 12;
string storeWorker = 13;
string msgService = 14;
string msgWorker = 15;
}

enum Level {
DEBUG = 0;
INFO = 1;
WARNING = 2;
ERROR = 3;
FATAL = 4;
DEBUG = 0;
INFO = 1;
WARNING = 2;
ERROR = 3;
FATAL = 4;
}

message Log {
optional string log_path = 1;
Level level = 2 [(validate.rules).enum.defined_only = true];
bool enable_console = 3;
optional string log_path = 1;
Level level = 2 [(validate.rules).enum.defined_only = true];
bool enable_console = 3;
}

message Redis {
string addr = 1;
string password = 2;
int32 max_conns = 3;
int32 min_idle_conns = 4;
// range: [10ms,10s]
google.protobuf.Duration dial_timeout = 5 [(validate.rules).duration = {
gte: {nanos: 10000000, seconds: 0},
lte: {seconds: 10}
}];
// range: [10ms,10s]
google.protobuf.Duration idle_timeout = 6 [(validate.rules).duration = {
gte: {nanos: 10000000, seconds: 0},
lte: {seconds: 10}
}];
string addr = 1;
string password = 2;
int32 max_conns = 3;
int32 min_idle_conns = 4;
// range: [10ms,10s]
google.protobuf.Duration dial_timeout = 5 [(validate.rules).duration = {
gte: {
nanos: 10000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
// range: [10ms,10s]
google.protobuf.Duration idle_timeout = 6 [(validate.rules).duration = {
gte: {
nanos: 10000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
}

message MQ {
repeated string addr = 1;
int32 max_retry = 2;
repeated string addr = 1;
int32 max_retry = 2;
}

message MySQL {
string addr = 1;
string user = 2;
string password = 3;
string db = 4;
int32 max_idle_conns = 5;
int32 max_open_conns = 6;
// range: [10ms,10s]
google.protobuf.Duration idle_timeout = 7 [(validate.rules).duration = {
gte: {nanos: 1000000, seconds: 0},
lte: {seconds: 10}
}];
// range: [10ms,10s]
google.protobuf.Duration open_timeout = 8 [(validate.rules).duration = {
gte: {nanos: 1000000, seconds: 0},
lte: {seconds: 10}
}];
}
string addr = 1;
string user = 2;
string password = 3;
string db = 4;
int32 max_idle_conns = 5;
int32 max_open_conns = 6;
// range: [10ms,10s]
google.protobuf.Duration idle_timeout = 7 [(validate.rules).duration = {
gte: {
nanos: 1000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
// range: [10ms,10s]
google.protobuf.Duration open_timeout = 8 [(validate.rules).duration = {
gte: {
nanos: 1000000,
seconds: 0
},
lte: {
seconds: 10
}
}];
}
Loading

0 comments on commit 1b0b6e7

Please sign in to comment.