golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.66k stars 1.58k forks source link

how to share a .proto file in diffenent go project with mod pattern #1496

Closed someview closed 1 year ago

someview commented 1 year ago

Situation:

// common.proto
syntax = "proto3";
option go_package = "MsgHeader";
message Header {
  string name = 1;
}
// aaa_project.proto that will be used in aaa project  with go mod pattern:
syntax = "proto3";
option go_package = "aaa";

import "common.proto";  // 导入其他包的 proto 文件
service aaaService {
  rpc OnPrivateMessage(stream msg) returns (stream msg) {}  //上行私聊消息
}

// b_project.proto
// bbb_project.proto that will be used in aaa project  with go mod pattern:
syntax = "proto3";
option go_package = "bbb";
import "common.proto";  // 导入其他包的 proto 文件
service bbbService {
  rpc OnPrivateMessage(stream msg) returns (stream msg) {}  //上行私聊消息
}

How to use common.proto for both aaa project and bbb project:they are diffenent fgo mods Is there any way to share the same msg definition for go diffenent project with mod pattern

puellanivis commented 1 year ago

The common.proto file has to be shared from a common source.