diff --git a/.gitignore b/.gitignore index f08a104..3977269 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,7 @@ config/override.toml bin/ dist.zip -frontend/dist/ \ No newline at end of file +frontend/dist/ + +# Ignore generated files +*.pb.go \ No newline at end of file diff --git a/Makefile b/Makefile index b86055c..bf85158 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,17 @@ get-front: .PHONY: install-tools install-tools: go install github.com/swaggo/swag/cmd/swag@latest + @# Referencing https://grpc.io/docs/protoc-installation/ + @./script/install-protoc.sh + @# Track https://grpc.io/docs/languages/go/quickstart/ for update + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 + +.PHONY: gen-proto +gen-proto: install-tools + protoc --go_out=. --go_opt=paths=source_relative \ + --go-grpc_out=. --go-grpc_opt=paths=source_relative \ + service/proto/*.proto .PHONY: build build: install-tools diff --git a/docker/oj-lab-platform.dockerfile b/docker/oj-lab-platform.dockerfile index 3c651cd..55a7bfa 100644 --- a/docker/oj-lab-platform.dockerfile +++ b/docker/oj-lab-platform.dockerfile @@ -5,6 +5,7 @@ COPY core/ /usr/src/core/ COPY service/ /usr/src/service/ COPY go.mod /usr/src/go.mod COPY go.sum /usr/src/go.sum +COPY script/ /usr/src/script/ COPY Makefile /usr/src/Makefile WORKDIR /usr/src diff --git a/go.mod b/go.mod index 06d1bcb..0f79b00 100644 --- a/go.mod +++ b/go.mod @@ -50,6 +50,8 @@ require ( golang.org/x/arch v0.4.0 // indirect golang.org/x/time v0.1.0 // indirect golang.org/x/tools v0.7.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/grpc v1.58.2 gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -84,5 +86,5 @@ require ( golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + google.golang.org/protobuf v1.31.0 ) diff --git a/go.sum b/go.sum index 8c84212..906a896 100644 --- a/go.sum +++ b/go.sum @@ -623,6 +623,8 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -639,6 +641,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/script/install-protoc.sh b/script/install-protoc.sh new file mode 100755 index 0000000..4345efd --- /dev/null +++ b/script/install-protoc.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Check if protoc is installed +if ! [ -x "$(command -v protoc)" ]; then + echo "Installing protoc" + # Check has sudo + if ! [ -x "$(command -v sudo)" ]; then + apt-get install -y protobuf-compiler + else + sudo apt-get install -y protobuf-compiler + fi +else + echo "protoc is already installed" +fi \ No newline at end of file diff --git a/service/proto/oj_lab_stream.proto b/service/proto/oj_lab_stream.proto new file mode 100644 index 0000000..5cf4203 --- /dev/null +++ b/service/proto/oj_lab_stream.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package oj_lab_stream.protos; + +option go_package = "github.com/OJ-lab/oj-lab-services/service/proto"; + +service Messaging { + rpc StartStream (StreamRequest) returns (stream StreamResponse) {} +} + +message StreamRequest { + string id = 1; +} + +message StreamResponse { + string id = 1; + string message = 2; +}