merge.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Check if directory parameter is provided
  3. if [ $# -eq 0 ]; then
  4. PROTO_DIR="." # Default to current directory
  5. else
  6. PROTO_DIR="$1" # Use the provided directory
  7. fi
  8. # Output file
  9. OUTPUT_FILE="${PROTO_DIR}/gorpc.proto"
  10. # Delete the output file if it already exists
  11. if [ -f "$OUTPUT_FILE" ]; then
  12. rm "$OUTPUT_FILE"
  13. echo "Deleted existing $OUTPUT_FILE"
  14. fi
  15. # Create the header part in the output file
  16. cat >"$OUTPUT_FILE" <<'EOL'
  17. syntax = "proto3";
  18. package gorpc;
  19. option go_package = "./pb";
  20. EOL
  21. # First add constant.proto content after the header
  22. grep -v 'syntax\|package\|option go_package' constant.proto >>"$OUTPUT_FILE"
  23. # First add common.proto content after the header
  24. grep -v 'syntax\|package\|option go_package\|import "pb/constant.proto"' common.proto >>"$OUTPUT_FILE"
  25. # Then append all other proto files
  26. for file in "$PROTO_DIR"/*.proto; do
  27. # Skip common.proto and the output file itself
  28. if [[ "$(basename "$file")" != "common.proto" && "$(basename "$file")" != "constant.proto" && "$(basename "$file")" != "gorpc.proto" ]]; then
  29. echo "Processing $(basename "$file")..."
  30. # Skip the header part and both common.proto and constant.proto imports
  31. grep -v 'syntax\|package\|option go_package\|import "pb/common.proto"\|import "pb/constant.proto"' "$file" >>"$OUTPUT_FILE"
  32. fi
  33. done
  34. echo "Proto files have been merged into $OUTPUT_FILE"
  35. goctl rpc protoc gorpc.proto \
  36. --go_out=./ \
  37. --go-grpc_out=./ \
  38. --zrpc_out=./tmp_generate \
  39. -m \
  40. --style go_zero
  41. if [ -d "./client" ]; then
  42. echo "Removing existing client directory..."
  43. rm -rf ./client
  44. fi
  45. cp -r ./tmp_generate/client ./client
  46. rm -rf ./tmp_generate
  47. go mod tidy