Если кто-то ответит на этот вопрос:
func registerProtoFile(src_dir string, filename string) error {
// First, convert the .proto file to a file descriptor set
tmp_file := filename + "tmp.pb"
cmd := exec.Command("protoc",
"--descriptor_set_out=" + tmp_file,
"-I"+src_dir
path.Join(src_dir, filename))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
defer os.Remove(tmp_file)
// Now load that temporary file as a file descriptor set protobuf
protoFile, err := ioutil.ReadFile(tmp_file)
if err != nil {
return err
}
pb_set := new(descriptorpb.FileDescriptorSet)
if err := proto.Unmarshal(protoFile, pb_set); err != nil {
return err
}
// We know protoc was invoked with a single .proto file
pb := pb_set.GetFile()[0]
// Initialize the File descriptor object
fd, err := protodesc.NewFile(pb, protoregistry.GlobalFiles)
if err != nil {
return err
}
// and finally register it.
return protoregistry.GlobalFiles.RegisterFile(fd)
}