diff --git a/README.md b/README.md index 35ed132e..f7dad62b 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -# protocol \ No newline at end of file +# protocol + +```shell +go install google.golang.org/protobuf/cmd/protoc-gen-go@latest +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest +``` + +More to read [regenerate-grpc-code](https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code). \ No newline at end of file diff --git a/gen.cmd b/gen.cmd index 1d44544c..c18543e0 100644 --- a/gen.cmd +++ b/gen.cmd @@ -6,17 +6,27 @@ set "PROTO_NAMES=auth conversation errinfo relation group jssdk msg msggateway p rem Loop through each element in the array for %%i in (%PROTO_NAMES%) do ( - protoc --go_out=plugins=grpc:./%%i --go_opt=module=github.com/openimsdk/protocol/%%i %%i/%%i.proto + protoc --go_out=./%%i --go_opt=module=github.com/openimsdk/protocol/%%i %%i/%%i.proto if ERRORLEVEL 1 ( echo error processing %%i.proto exit /b %ERRORLEVEL% ) ) +rem Generate Go-grpc code (optional, currently commented out) + +rem for %%i in (%PROTO_NAMES%) do ( +rem protoc --go-grpc_out=./%%i --go-grpc_opt=module=github.com/openimsdk/protocol/%%i %%i/%%i.proto +rem if ERRORLEVEL 1 ( +rem echo error processing %%i.proto (go-grpc_out) +rem exit /b %ERRORLEVEL% +rem ) +rem ) + + rem Replace "omitempty" in *.pb.go files with UTF-8 encoding for /r %%f in (*.pb.go) do ( powershell -Command "(Get-Content -Path '%%f' -Encoding UTF8) -replace ',omitempty\"`"', '\"`"' | Set-Content -Path '%%f' -Encoding UTF8" ) - endlocal diff --git a/gen.sh b/gen.sh index a9e389c3..fa103c88 100755 --- a/gen.sh +++ b/gen.sh @@ -1,17 +1,3 @@ -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - PROTO_NAMES=( "auth" "conversation" @@ -31,13 +17,23 @@ PROTO_NAMES=( ) for name in "${PROTO_NAMES[@]}"; do - protoc --go_out=plugins=grpc:./${name} --go_opt=module=github.com/openimsdk/protocol/${name} ${name}/${name}.proto + protoc --go_out=./${name} --go_opt=module=github.com/openimsdk/protocol/${name} ${name}/${name}.proto if [ $? -ne 0 ]; then - echo "error processing ${name}.proto" + echo "error processing ${name}.proto (go_out)" exit $? fi done +# generate go-grpc + +# for name in "${PROTO_NAMES[@]}"; do +# protoc --go-grpc_out=./${name} --go-grpc_opt=module=github.com/openimsdk/protocol/${name} ${name}/${name}.proto +# if [ $? -ne 0 ]; then +# echo "error processing ${name}.proto (go-grpc_out)" +# exit $? +# fi +# done + if [ "$(uname -s)" == "Darwin" ]; then find . -type f -name '*.pb.go' -exec sed -i '' 's/,omitempty"`/\"\`/g' {} + else diff --git a/gen_openmeeting.sh b/gen_openmeeting.sh index 00de5914..d31a2f13 100755 --- a/gen_openmeeting.sh +++ b/gen_openmeeting.sh @@ -1,17 +1,3 @@ -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - PROTO_NAMES=( "admin" "user" @@ -19,13 +5,23 @@ PROTO_NAMES=( ) for name in "${PROTO_NAMES[@]}"; do - protoc --go_out=plugins=grpc:./openmeeting/${name} --go_opt=module=github.com/openimsdk/protocol/openmeeting/${name} openmeeting/${name}/${name}.proto + protoc --go_out=./openmeeting/${name} --go_opt=module=github.com/openimsdk/protocol/openmeeting/${name} openmeeting/${name}/${name}.proto if [ $? -ne 0 ]; then - echo "error processing ${name}.proto" + echo "error processing ${name}.proto (go_out)" exit $? fi done +# generate go-grpc + +# for name in "${PROTO_NAMES[@]}"; do +# protoc --go-grpc_out=./openmeeting/${name} --go_opt=module=github.com/openimsdk/protocol/openmeeting/${name} openmeeting/${name}/${name}.proto +# if [ $? -ne 0 ]; then +# echo "error processing ${name}.proto (go-grpc_out)" +# exit $? +# fi +# done + if [ "$(uname -s)" == "Darwin" ]; then find . -type f -name '*.pb.go' -exec sed -i '' 's/,omitempty"`/\"\`/g' {} + else