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

Update deprecated probuf lib and methods, remove jhump/protoreflect d… #413

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
ifeq ($(OS), Windows_NT)
BIN := pitaya-cli.exe
XK6_BIN := k6.exe
MKFOLDER := if not exist "build" mkdir build
GREP_CMD := findstr /V
else
BIN := pitaya-cli
XK6_BIN := k6
MKFOLDER := mkdir -p build
GREP_CMD := grep -v
endif

TESTABLE_PACKAGES = `go list ./... | $(GREP_CMD) examples | $(GREP_CMD) constants | $(GREP_CMD) mocks | $(GREP_CMD) helpers | $(GREP_CMD) interfaces | $(GREP_CMD) protos | $(GREP_CMD) e2e | $(GREP_CMD) benchmark`

.PHONY: all build

setup: init-submodules
@go get ./...

build:
@$(MKFOLDER)
@mkdir -p build
@go build -o build/$(BIN) .
@echo "build pitaya-cli at ./build/$(BIN)"

Expand All @@ -34,7 +34,7 @@ setup-ci:

setup-protobuf-macos:
@brew install protobuf
@go install github.com/golang/protobuf/protoc-gen-go@latest
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

run-jaeger-aio:
@docker compose -f ./examples/testing/docker-compose-jaeger.yml up -d
Expand All @@ -53,10 +53,10 @@ run-cluster-example-frontend:
@PITAYA_METRICS_PROMETHEUS_PORT=9090 go run examples/demo/cluster/main.go

run-cluster-protobuf-frontend-example:
@cd examples/demo/cluster_protobuf && go run main.go
@cd examples/demo/cluster && go run main.go -serializer=protobuf

run-cluster-protobuf-backend-example:
@cd examples/demo/cluster_protobuf && go run main.go --port 3251 --type room --frontend=false
@cd examples/demo/cluster && go run main.go -serializer=protobuf --port 3251 --type room --frontend=false

run-cluster-example-backend:
@PITAYA_METRICS_PROMETHEUS_PORT=9091 go run examples/demo/cluster/main.go --port 3251 --type room --frontend=false
Expand All @@ -83,12 +83,14 @@ run-rate-limiting-example:
@go run examples/demo/rate_limiting/main.go

protos-compile-demo:
@protoc -I examples/demo/protos examples/demo/protos/*.proto --go_out=.
@protoc -I examples/demo/cluster_protos examples/demo/cluster_protos/*.proto --go_out=.
@protoc -I examples/demo/worker/protos examples/demo/worker/protos/*.proto --go_out=.
@protoc -I examples/testing/protos examples/testing/protos/*.proto --go_out=.

protos-compile:
@cd benchmark/testdata && ./gen_proto.sh
@protoc -I pitaya-protos/ pitaya-protos/*.proto --go_out=plugins=grpc:protos
@protoc -I pitaya-protos/test pitaya-protos/test/*.proto --go_out=protos/test
@protoc -I pitaya-protos/ pitaya-protos/*.proto --go-grpc_out=require_unimplemented_servers=false,paths=source_relative:./pkg/protos --go_out=paths=source_relative:./pkg/protos
@protoc -I pitaya-protos/test pitaya-protos/test/*.proto --go_out=paths=source_relative:./pkg/protos/test

rm-test-temp-files:
@rm -f cluster/127.0.0.1* 127.0.0.1*
Expand Down
2 changes: 1 addition & 1 deletion benchmark/testdata/gen_proto.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
protoc --go_out . *.proto
protoc --go_out=paths=source_relative:. *.proto
248 changes: 171 additions & 77 deletions benchmark/testdata/test.pb.go

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

3 changes: 2 additions & 1 deletion benchmark/testdata/test.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
syntax = "proto3";
package testdata;
option go_package = "github.com/topfreegames/pitaya/benchmark/testdata";

message Ping {
string Content = 1;
}

message Pong {
string Content = 2;
}
}
12 changes: 12 additions & 0 deletions examples/demo/cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/topfreegames/pitaya/v3/pkg/config"
"github.com/topfreegames/pitaya/v3/pkg/groups"
"github.com/topfreegames/pitaya/v3/pkg/route"
"github.com/topfreegames/pitaya/v3/pkg/serialize/json"
"github.com/topfreegames/pitaya/v3/pkg/serialize/protobuf"
"github.com/topfreegames/pitaya/v3/pkg/tracing"
)

Expand Down Expand Up @@ -86,6 +88,7 @@ func main() {
port := flag.Int("port", 3250, "the port to listen")
svType := flag.String("type", "connector", "the server type")
isFrontend := flag.Bool("frontend", true, "if server is frontend")
serializer := flag.String("serializer", "json", "the serializer to use")

flag.Parse()

Expand All @@ -96,6 +99,15 @@ func main() {
tcp := acceptor.NewTCPAcceptor(fmt.Sprintf(":%d", *port))
builder.AddAcceptor(tcp)
}

if *serializer == "json" {
builder.Serializer = json.NewSerializer()
} else if *serializer == "protobuf" {
builder.Serializer = protobuf.NewSerializer()
} else {
panic("unknown serializer " + *serializer)
}

builder.Groups = groups.NewMemoryGroupService(builder.Config.Groups.Memory)
app = builder.Build()

Expand Down
Loading